-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreloadtab.js
67 lines (50 loc) · 1.52 KB
/
reloadtab.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
var reloadTabTimer = null;
function changeHoverText(tab, reloadMins) {
var currentDate = new Date();
var hours = currentDate.getHours();
var futureMins = currentDate.getMinutes() + reloadMins;
var secs = currentDate.getSeconds();
if (futureMins > 59){
hours += 1;
futureMins -= 60;
}
if (futureMins < 10) {
futureMins = "0" + futureMins;
}
if (hours > 23) {
hours = 0;
}
if (hours < 10) {
hours = "0" + hours;
}
if (secs < 10) {
secs = "0" + secs;
}
var dateStr = hours + ":" + futureMins + ":" + secs;
browser.browserAction.setTitle(
{'title': 'Will reload at: ' + dateStr, 'tabId': tab.id}
);
}
function activatedAddon(tab) {
var reloadMins = 5;
if (reloadTabTimer != null) {
clearTimeout(reloadTabTimer);
browser.browserAction.setIcon(
{'path': 'icons/icon-38.png', 'tabId': tab.id}
);
browser.browserAction.setTitle(
{'title': 'Reload this tab every ' + reloadMins + ' min', 'tabId': tab.id}
);
reloadTabTimer = null;
return;
}
browser.browserAction.setIcon(
{'path': 'icons/icon-red-38.png', 'tabId': tab.id}
);
changeHoverText(tab, reloadMins);
reloadTabTimer = setInterval(function() {
browser.tabs.reload(tab.id, {'bypassCache': true});
changeHoverText(tab, reloadMins);
}, reloadMins * 60 * 1000);
}
browser.browserAction.onClicked.addListener(activatedAddon);