forked from zchr/zoomies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (28 loc) · 762 Bytes
/
script.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
const SITES_KEY = "sites";
async function getSites() {
const { sites } = await chrome.storage.local.get(SITES_KEY);
if (sites == null) {
chrome.storage.local.set({ [SITES_KEY]: {} });
return {};
}
return sites;
}
async function init() {
const sites = await getSites();
// Mount tally
const { tally } = await chrome.storage.local.get("tally");
document.getElementById("tally").innerHTML = tally || 0;
// Mount all checkboxes
document.querySelectorAll("input[type=checkbox]").forEach((e) => {
e.checked = sites[e.name];
e.onchange = async function () {
chrome.storage.local.set({
[SITES_KEY]: {
...(await getSites()),
[e.name]: this.checked,
},
});
};
});
}
init();