-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground-f5.js
More file actions
46 lines (35 loc) · 867 Bytes
/
background-f5.js
File metadata and controls
46 lines (35 loc) · 867 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
40
41
42
43
44
45
46
var tabs = {};
function addTab(tabId, delay) {
if (tabId in tabs) return;
var intervalId = window.setInterval(() => {
browser.tabs.reload(tabId);
}, delay);
tabs[tabId] = intervalId;
}
function removeTab(tabId) {
if (!(tabId in tabs)) return;
window.clearInterval(tabs[tabId]);
delete tabs[tabId];
}
browser.runtime.onMessage.addListener((msg, _, sendResponse) => {
switch (msg.type) {
case 'add':
addTab(msg.tabId, msg.delay);
break;
case 'remove':
removeTab(msg.tabId);
break;
case 'status':
sendResponse({
type: 'statusResponse',
reloading: (msg.tabId in tabs)
});
break;
}
});
browser.tabs.onActivated.addListener((info) => {
var green = info.tabId in tabs ? '-green' : '';
browser.browserAction.setIcon({
path: `icons/reload${green}-48.png`
});
});