-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackground.js
28 lines (27 loc) · 928 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
var enabled;
function toggleState() {
enabled = !enabled;
chrome.storage.local.set({ enabled: enabled });
}
function updateIcon() {
chrome.action.setIcon({ path: enabled? 'icons/thumb-48.png' : 'icons/disable-48.png' });
chrome.action.setTitle({ title: enabled? 'Image Data (on)' : 'Image Data (off)' });
}
function stateChanged(changes) {
//only update on enabled change
if(changes.enabled) {
//reset to enabled state on factory reset otherwise use newValue
enabled = changes.enabled.newValue === undefined ? true : changes.enabled.newValue;
updateIcon();
}
}
function readStorage(storage) {
enabled = storage.enabled;
updateIcon();
}
//toggle enabled when toolbar button is clicked
chrome.action.onClicked.addListener(toggleState);
//update on enabled state change
chrome.storage.onChanged.addListener(stateChanged);
//on browser startup get prior state
chrome.storage.local.get({enabled: true}, readStorage);