-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
51 lines (45 loc) · 1.19 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
chrome.storage.local.get({'notificationSetting': 'none'},
function (data) {
setNotificationSetting(data['notificationSetting']);
}
);
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.storage.local.get({'notificationSetting': 'none'},
function (data) {
if (data['notificationSetting'] != 'block') {
setNotificationSetting('block');
} else {
setNotificationSetting('none');
}
}
);
});
function setNotificationSetting(setting) {
chrome.storage.local.set({'notificationSetting': setting});
if (setting == 'block') {
chrome.contentSettings['notifications'].set({
'primaryPattern': '<all_urls>',
'setting': setting
});
chrome.browserAction.setIcon({
'path': {
'19': 'icon-off-19.png',
'38': 'icon-off-38.png'
}
});
chrome.browserAction.setTitle({
'title': 'Unmute notifications'
});
} else { // none
chrome.contentSettings['notifications'].clear({});
chrome.browserAction.setIcon({
'path': {
'19': 'icon-on-19.png',
'38': 'icon-on-38.png'
}
});
chrome.browserAction.setTitle({
'title': 'Mute notifications'
});
}
}