-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
36 lines (29 loc) · 865 Bytes
/
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
var state;
chrome.storage.sync.get({state: true}, function(data) {
state = data.state;
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
if (namespace == 'sync' && 'state' in changes) {
state = changes.state.newValue;
}
});
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.action == 'listenForReady') {
sendResponse({action: 'addClasses', state: state});
}
});
chrome.webNavigation.onCommitted.addListener(function(navDetails) {
var repetitions = 20;
var delayMs = 20;
send();
function send() {
chrome.tabs.sendMessage(
navDetails.tabId,
{action: 'addClasses', data: state},
{frameId: navDetails.frameId}
);
if (--repetitions) {
setTimeout(send, delayMs);
}
}
});