-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathbackground.js
63 lines (53 loc) · 1.88 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use-strict';
//const DEBUG = true;
/* function toI18n(str) {
return str.replace(/__MSG_(\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : '';
});
} */
// Default options
const defaultOptions = {
'open-in-new-tab': true,
//'open-search-by-in-new-tab': true,
//'show-globe-icon': true,
//'hide-images-subject-to-copyright': false,
'manually-set-button-text': false,
'no-referrer': false,
'button-text-view-image': '',
//'button-text-search-by-image': '',
//'context-menu-search-by-image': true,
//'context-menu-search-by-image-new-tab': false,
};
// Save default options to storage
chrome.storage.sync.get('defaultOptions', function () {
chrome.storage.sync.set({ defaultOptions });
});
// Deprecated for now, user feedback is that it's not useful
/* chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.get(['options', 'defaultOptions'], (storage) => {
if (!storage.hasOwnProperty('options')) {
storage.options = {};
}
const options = Object.assign(storage.defaultOptions, storage.options);
// Setup "Search by image" context menu item
if (options['context-menu-search-by-image']) {
chrome.contextMenus.create(
{
'id': 'ViewImage-SearchByImage',
'title': toI18n('__MSG_searchImage__'),
'contexts': ['image'],
}
);
}
});
}); */
// See above deprecation note
/* chrome.contextMenus.onClicked.addListener((info, tab) => {
if (DEBUG)
console.log('ViewImage: Search By Image context menu item clicked.', info, tab);
if (info.menuItemId === 'ViewImage-SearchByImage') {
chrome.tabs.create({
url: `https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}`,
});
}
}); */