-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (30 loc) · 1.04 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
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ExtensionOn: true, Opacity: 0.8});
});
chrome.runtime.onMessage.addListener((msg, _1, _2) => {
if (msg == 'Convert success') {
chrome.tabs.query({}, (tabs) =>
tabs.forEach((tab) =>
chrome.tabs.sendMessage(tab.id, 'ImgSrc')
)
);
}
});
function genericOnClick(info, tab) {
if (new URL(info.srcUrl).protocol != 'file:') {
chrome.storage.local.set({ImgSrc: info.srcUrl}, () =>
chrome.tabs.query({}, (tabs) =>
tabs.forEach((tab) =>
chrome.tabs.sendMessage(tab.id, 'ExtensionOn')
)
)
);
} else {
chrome.tabs.query({active: true}, (tabs) =>
tabs.forEach((tab) =>
chrome.tabs.sendMessage(tab.id, 'Convert the image to url')
)
)
}
}
var id = chrome.contextMenus.create({'title': 'Choose this image as background', 'contexts':['image'], 'onclick': genericOnClick});