forked from sorenlouv/github-widescreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground-scripts.js
More file actions
39 lines (31 loc) · 919 Bytes
/
background-scripts.js
File metadata and controls
39 lines (31 loc) · 919 Bytes
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
/*globals chrome */
function updateIcon(state){
var color = state ? [255, 0, 0, 255] : [190, 190, 190, 230];
var text = state ? 'On' : 'Off';
chrome.action.setBadgeBackgroundColor({color: color});
chrome.action.setBadgeText({text: text});
}
function setState(state){
chrome.storage.sync.set({state: state});
}
function getState(callback){
chrome.storage.sync.get('state', function(data) {
callback(data.state);
});
}
chrome.action.onClicked.addListener(function () {
getState(function(state){
var newState = !state;
updateIcon(newState);
setState(newState);
});
});
getState(function(state) {
updateIcon(state);
});
chrome.webNavigation.onDOMContentLoaded.addListener(details => {
chrome.tabs.sendMessage(details.tabId, { action: "checkState" });
});
chrome.webNavigation.onHistoryStateUpdated.addListener(details => {
chrome.tabs.sendMessage(details.tabId, { action: "checkState" });
});