-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.js
54 lines (44 loc) · 1.77 KB
/
options.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
const storage = {
get: async (key) => (await chrome.storage.sync.get([key]))[key],
set: async (config) => await chrome.storage.sync.set(config),
};
document.addEventListener("DOMContentLoaded", async () => {
await restore();
syncUi();
findRelativeNumberToggler().addEventListener("change", save);
findRelativeNumberToggler().addEventListener("change", syncUi);
findRelativeNumberSignToggler().addEventListener("change", save);
});
async function restore() {
const useRelativeNumber = await storage.get("useRelativeNumber");
findRelativeNumberToggler().checked = useRelativeNumber ?? false;
const useRelativeNumberSign = await storage.get("useRelativeNumberSign");
findRelativeNumberSignToggler().checked = useRelativeNumberSign ?? false;
}
async function save(event) {
if (event.target.id === "relative-number-toggler") {
const useRelativeNumber = findRelativeNumberToggler().checked;
await storage.set({ useRelativeNumber });
}
if (event.target.id === "relative-number-sign-toggler") {
const useRelativeNumberSign = findRelativeNumberSignToggler().checked;
await storage.set({ useRelativeNumberSign });
}
}
function syncUi() {
const relativeNumberToggler = findRelativeNumberToggler();
const relativeNumberSignToggler = findRelativeNumberSignToggler();
if (relativeNumberToggler.checked) {
relativeNumberSignToggler.disabled = false;
relativeNumberSignToggler.closest("label").ariaDisabled = false;
} else {
relativeNumberSignToggler.disabled = true;
relativeNumberSignToggler.closest("label").ariaDisabled = true;
}
}
function findRelativeNumberToggler() {
return document.querySelector("#relative-number-toggler");
}
function findRelativeNumberSignToggler() {
return document.querySelector("#relative-number-sign-toggler");
}