-
Notifications
You must be signed in to change notification settings - Fork 0
/
f5.js
79 lines (69 loc) · 1.57 KB
/
f5.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
function addTab(tabId, delay) {
browser.runtime.sendMessage({
type: 'add',
tabId: tabId,
delay: delay
});
}
function removeTab(tabId) {
browser.runtime.sendMessage({
type: 'remove',
tabId: tabId
});
}
function loadStatus(tabId) {
browser.runtime.sendMessage({
type: 'status',
tabId: tabId
}).then((msg) => {
if (msg.type !== 'statusResponse') return;
if (msg.reloading) showReloading();
else showNotReloading();
});
}
function elem(id) {
return document.getElementById(id);
}
function showReloading() {
browser.browserAction.setIcon({
path: 'icons/reload-green-48.png'
});
elem('input-delay').style.display = 'none';
elem('btn-add').style.display = 'none';
elem('btn-remove').style.display = '';
}
function showNotReloading() {
browser.browserAction.setIcon({
path: 'icons/reload-48.png'
});
elem('input-delay').style.display = '';
elem('btn-add').style.display = '';
elem('btn-remove').style.display = 'none';
}
document.addEventListener('click', (e) => {
var activeTab = browser.tabs.query({
active: true,
currentWindow: true
});
if (e.target.id === 'btn-add') {
var delay = elem('input-delay').value;
if (delay > 0) {
activeTab.then((tabs) => {
addTab(tabs[0].id, delay);
showReloading();
});
}
}
else if (e.target.id === 'btn-remove') {
activeTab.then((tabs) => {
removeTab(tabs[0].id);
showNotReloading();
});
}
});
browser.tabs.query({
active: true,
currentWindow: true
}).then((tabs) => {
loadStatus(tabs[0].id);
});