-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
popup.js
65 lines (59 loc) · 1.76 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
document.getElementById('RemoveMessages').addEventListener('click', () => {
chrome.runtime.sendMessage({
action: 'REMOVE',
});
});
document.getElementById('Stop').addEventListener('click', () => {
chrome.runtime.sendMessage({
action: 'STOP',
});
});
// If the active tab was previously cleared, update the popup with the info.
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.storage.local.get([tabs[0].url], (result) => {
if (!result || Object.keys(result).length === 0) return;
console.log('Found storage for url: ', result);
if ('lastCleared' in result[tabs[0].url]) {
document.getElementById('LastCleared').innerHTML =
'Last Cleared: ' + result[tabs[0].url]['lastCleared'];
}
});
});
// Make sure the user is using messenger.com.
const messengers = [
'https://www.messenger.com',
'http://www.messenger.com',
'https://messenger.com/',
'http://messenger.com/',
];
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
(tabs) => {
const url = tabs[0].url;
if (!messengers.some((m) => url.startsWith(m))) {
alert(
`ERROR: Shoot the Messenger must be used on messenger.com, currently on ${url}. This extension will not work as intended.`,
);
}
},
);
document.getElementById('Delay').addEventListener('input', (e) => {
chrome.runtime.sendMessage({
action: 'UPDATE_DELAY',
data: e.target.value,
});
});
document.getElementById('Mode').addEventListener('input', (e) => {
chrome.runtime.sendMessage({
action: 'UPDATE_MODE',
data: e.target.value,
});
});
// Send over defaults to clear whatever the prior state is from local storage.
chrome.runtime.sendMessage({
action: 'UPDATE_DELAY',
data: document.getElementById('Delay').value,
});