-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
52 lines (48 loc) · 1.62 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
chrome.storage.local.get(['onOffStatus'], function (result) {
if (result.onOffStatus) {
activateScript();
}
});
chrome.storage.onChanged.addListener(function (changes, namespace) {
var onOffStatus = changes.onOffStatus
if (onOffStatus && onOffStatus.newValue) {
activateScript();
return;
}
deactivateScript();
});
function injectTheScript(tabId, changeInfo) {
if (changeInfo.status === 'complete') {
chrome.tabs.executeScript(tabId, {
file: 'event_script.js'
});
}
}
function activateScript() {
chrome.windows.getAll(null, function (windows) {
for (var j = 0; j < windows.length; ++j) {
chrome.tabs.getAllInWindow(windows[j].id, function (tabs) {
for (var i = 0; i < tabs.length; ++i) {
if (tabs[i].url.indexOf("chrome://") != 0) {
chrome.tabs.executeScript(tabs[i].id, {file: 'event_script.js'});
}
}
});
}
});
chrome.tabs.onUpdated.addListener(injectTheScript);
}
function deactivateScript() {
chrome.windows.getAll(null, function (windows) {
for (var j = 0; j < windows.length; ++j) {
chrome.tabs.getAllInWindow(windows[j].id, function (tabs) {
for (var i = 0; i < tabs.length; ++i) {
if (tabs[i].url.indexOf("chrome://") != 0) {
chrome.tabs.executeScript(tabs[i].id, {file: 'remove_script.js'});
}
}
});
}
});
chrome.tabs.onUpdated.removeListener(injectTheScript);
}