-
Notifications
You must be signed in to change notification settings - Fork 4
/
background.js
35 lines (33 loc) · 1.28 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
// ref: http://stackoverflow.com/questions/18740932
chrome.action.onClicked.addListener(function(tab) {
chrome.action.setPopup({popup: ''});
chrome.storage.local.get('disabled', function (data) {
if (data.hasOwnProperty('disabled')) {
if (!data.disabled) {
chrome.action.setIcon({path: 'icon-off.png'});
chrome.storage.local.set({'disabled': true});
} else {
chrome.action.setIcon({path: 'icon.png'});
chrome.storage.local.set({'disabled': false});
}
}
});
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if ('getDisabled' === request.msg) {
chrome.storage.local.get('disabled', function (data) {
if (data.hasOwnProperty('disabled')) {
if (data.disabled) {
chrome.action.setIcon({path: 'icon-off.png'});
} else {
chrome.action.setIcon({path: 'icon.png'});
}
} else {
chrome.storage.local.set({'disabled': false});
}
sendResponse(data);
});
// note: must return true, otherwise sendResponse() won't work
return true;
}
});