-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
111 lines (99 loc) · 3.04 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
chrome.runtime.onMessage.addListener(
function(request, sender) {
if (request.todo === "toggleIcon") {
toggleIcon(request.state, sender.tab);
} else if (request.todo === "togglePause") {
togglePause(sender.tab);
}
}
)
function toggleIcon(desiredState, tab) {
if (desiredState === 'on') {
chrome.browserAction.setIcon({
tabId: tab.id,
path: {
"16": "icons/house-16.png",
"32": "icons/house-32.png",
"48": "icons/house-48.png",
"128": "icons/house-128.png",
"256": "icons/house-256.png"
},
});
chrome.browserAction.setPopup({
tabId: tab.id,
popup: 'popups/on.html',
});
chrome.browserAction.setBadgeText({
"text": ""
});
} else if (desiredState === 'off') {
chrome.browserAction.setIcon({
tabId: tab.id,
path: {
"16": "icons/house-disabled-16.png",
"32": "icons/house-disabled-32.png",
"48": "icons/house-disabled-48.png",
"128": "icons/house-disabled-128.png",
"256": "icons/house-disabled-256.png"
},
});
chrome.browserAction.setPopup({
tabId: tab.id,
popup: 'popups/off.html',
});
chrome.browserAction.setBadgeText({
"text": ""
});
} else if (desiredState === 'alwaysOn') {
chrome.browserAction.setIcon({
tabId: tab.id,
path: {
"16": "icons/house-16.png",
"32": "icons/house-32.png",
"48": "icons/house-48.png",
"128": "icons/house-128.png",
"256": "icons/house-256.png"
},
});
chrome.browserAction.setPopup({
tabId: tab.id,
popup: 'popups/always-on.html',
});
chrome.browserAction.setBadgeText({
"text": ""
});
} else if (desiredState === 'paused') {
chrome.browserAction.setIcon({
tabId: tab.id,
path: {
"16": "icons/house-disabled-16.png",
"32": "icons/house-disabled-32.png",
"48": "icons/house-disabled-48.png",
"128": "icons/house-disabled-128.png",
"256": "icons/house-disabled-256.png"
},
});
chrome.browserAction.setPopup({
tabId: tab.id,
popup: 'popups/paused.html',
});
chrome.browserAction.setBadgeText({
"text": "ll"
});
}
}
function togglePause(tab) {
getSettings(function(items) {
if (items.paused == true) {
newState = false;
} else if (items.paused == false) {
newState = true;
chrome.browserAction.setBadgeText({
"text": "ll"
});
}
chrome.storage.sync.set({
paused: newState
});
});
}