forked from threethan/Better-Darker-Docs-WebExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
39 lines (33 loc) · 1.34 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
function saveOptions(e) {
e.preventDefault();
var dm;
if (document.querySelector("#dm_off") .checked) dm = "off" ;
if (document.querySelector("#dm_auto") .checked) dm = "auto" ;
if (document.querySelector("#dm_always").checked) dm = "always";
let sp = document.querySelector("#sp_switch").checked;
browser.storage.sync.set({
darkmode: dm,
subpixel: sp,
});
}
function restoreOptions() {
function setSubpixelChoice(result) {
document.querySelector("#sp_switch").checked = result.subpixel == null ? true : result.subpixel;
}
function setDarkmodeChoice(result) {
let dm = result.darkmode || "auto";
document.querySelector("#dm_off") .checked = dm == "off" ;
document.querySelector("#dm_auto") .checked = dm == "auto" ;
document.querySelector("#dm_always").checked = dm == "always";
}
function onError(error) {
console.log(`BDD Options Error: ${error}`);
}
let spgetting = browser.storage.sync.get("subpixel");
spgetting.then(setSubpixelChoice, onError);
let dmgetting = browser.storage.sync.get("darkmode");
dmgetting.then(setDarkmodeChoice, onError);
}
restoreOptions();
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("change", saveOptions);