-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
66 lines (52 loc) · 1.66 KB
/
popup.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
'use strict';
var inteval_key = "inteval";
var auto_refresh_key = "auto_refresh";
function updateToggleText(tab_id) {
var ar_key = auto_refresh_key + tab_id;
var btn_text = localStorage[ar_key] == "true" ? "Stop" : "Start";
autoRefreshToggle.value = btn_text;
}
function delayedReloadRecursive(tab_id) {
var ar_key = auto_refresh_key + tab_id;
var it_key = inteval_key + tab_id;
if (localStorage[ar_key] == "true") {
var inteval = Number(localStorage[it_key]);
setTimeout(function() {
chrome.tabs.reload(tab_id);
delayedReloadRecursive(tab_id);
}, inteval);
}
}
intevalNumber.onchange = function(event) {
if (event.target.value < 1) { event.target.value = 1; }
}
autoRefreshToggle.onclick = function(event) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab_id = tabs[0].id;
var ar_key = auto_refresh_key + tab_id;
var it_key = inteval_key + tab_id;
if (localStorage[ar_key] == "true") {
localStorage[ar_key] = "false";
intevalNumber.disabled = false;
} else {
localStorage[ar_key] = "true";
localStorage[it_key] = intevalNumber.value * 1000;
intevalNumber.disabled = true;
delayedReloadRecursive(tab_id);
}
updateToggleText(tab_id);
});
};
// Per Tab Initialization
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab_id = tabs[0].id;
var ar_key = auto_refresh_key + tab_id;
var it_key = inteval_key + tab_id;
if (!localStorage[ar_key]) {
localStorage[ar_key] = false;
}
if (localStorage[it_key]) {
intevalNumber.value = Number(localStorage[it_key]) / 1000;
}
updateToggleText(tab_id);
});