-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
69 lines (59 loc) · 1.54 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
64
65
66
67
68
checkElmKillaStatus(setIcon);
chrome.browserAction.onClicked.addListener(toggleElmKilla);
chrome.tabs.onUpdated.addListener(tabUpdated);
function initializeScript() {
verifyTabs(setStateAndRunScript);
};
function tabUpdated(tabID, changeInfo, tab) {
let isTabReady = changeInfo.status === 'complete';
checkElmKillaStatus((status) => {
if (isTabReady && status) {
runElmKilla(tab);
}
});
};
function setIcon(status) {
status ? setActiveIcon() : setInactiveIcon();
};
function runElmKilla(tab) {
if (tab.url.search(/https?:\/\//) === 0) {
chrome.tabs.executeScript(tab.id, { file: "./elm-killa-script.js" });
};
};
function toggleElmKilla() {
checkElmKillaStatus((status) => {
status = !status;
chrome.storage.local.set({ "elmKillaActive": status });
setIcon(status);
chrome.tabs.query({}, (tabs) => {
tabs.forEach((tab) => {
runElmKilla(tab);
});
});
});
};
function checkElmKillaStatus(callback) {
chrome.storage.local.get(["elmKillaActive"], function(result) {
callback(result.elmKillaActive);
});
}
function setInactiveIcon() {
chrome.browserAction.setIcon({
path : {
"16": "images/elm-lives16.png",
"32": "images/elm-lives32.png",
"48": "images/elm-lives48.png",
"128": "images/elm-lives128.png"
}
});
}
function setActiveIcon() {
chrome.browserAction.setIcon({
path : {
"16": "images/elm-dies16.png",
"32": "images/elm-dies32.png",
"48": "images/elm-dies48.png",
"128": "images/elm-dies128.png"
}
});
}