-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
30 lines (26 loc) · 1.04 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
document.addEventListener('DOMContentLoaded', function() {
const toggle = document.getElementById('blockingToggle');
// Get current tab's hostname
browser.tabs.query({active: true, currentWindow: true}).then(tabs => {
const url = new URL(tabs[0].url);
const hostname = url.hostname;
// Get current state
browser.storage.local.get(hostname).then(result => {
toggle.checked = result[hostname] !== false;
});
});
// Handle toggle changes
toggle.addEventListener('change', function() {
browser.tabs.query({active: true, currentWindow: true}).then(tabs => {
const url = new URL(tabs[0].url);
const hostname = url.hostname;
// Save state
let save = {};
save[hostname] = toggle.checked;
browser.storage.local.set(save).then(() => {
// Reload the current tab
browser.tabs.reload(tabs[0].id);
});
});
});
});