-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
79 lines (69 loc) · 2.61 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
67
68
69
70
71
72
73
74
75
76
77
78
79
// Get global stats
const escapeBlockingSwitch = document.getElementById('escapeBlockingSwitch');
escapeBlockingSwitch.onchange = onBlockingSwitchChange;
chrome.runtime.sendMessage(
{
type: 'getEscapeBlockingEnabled',
},
function(escapeBlockingEnabled) {
escapeBlockingSwitch.checked = escapeBlockingEnabled;
}
);
refreshPopup();
setTimeout(refreshPopup, 1000);
function onBlockingSwitchChange() {
let checked = document.getElementById('escapeBlockingSwitch').checked;
chrome.runtime.sendMessage(
{
type: 'setEscapeBlockingEnabled',
escapeBlockingEnabled: checked
}
);
}
function refreshPopup() {
chrome.runtime.sendMessage(
{
type: 'getGlobalCounts'
},
function(response) {
let total = Object.values(response).reduce((a, b) => a + b, 0);
document.getElementById('total').innerHTML = total;
document.getElementById('waybackMachineMetaRequest').innerHTML = response.waybackMachineMetaRequest;
document.getElementById('archiveRequest').innerHTML = response.archiveRequest;
document.getElementById('archiveEscape').innerHTML = response.archiveEscape;
document.getElementById('notOnArchive').innerHTML = response.notOnArchive;
document.getElementById('unclassifiedRequest').innerHTML = response.unclassifiedRequest;
}
);
var query = {
active: true,
currentWindow: true
};
chrome.tabs.query(query, (tabs) => {
if (tabs.length === 1) {
let tab = tabs[0];
console.log('got exactly 1 active tab');
document.getElementById('currentLocation').innerHTML = tab.url;
chrome.runtime.sendMessage(
{
type: 'getVisitForTab',
tab: tab
},
function(response) {
console.log(response);
let total = Object.values(response.counts).reduce((a, b) => a + b, 0);
document.getElementById('visitTotal').innerHTML = total;
document.getElementById('visitWaybackMachineMetaRequest').innerHTML = response.counts.waybackMachineMetaRequest;
document.getElementById('visitArchiveRequest').innerHTML = response.counts.archiveRequest;
document.getElementById('visitArchiveEscape').innerHTML = response.counts.archiveEscape;
document.getElementById('visitNotOnArchive').innerHTML = response.counts.notOnArchive;
document.getElementById('visitUnclassifiedRequest').innerHTML = response.counts.unclassifiedRequest;
}
);
} else if (tabs.length === 0) {
console.log('no active tab found');
} else if (tabs.length > 1) {
console.log('multiple active tabs found');
}
});
}