-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions-manager.js
43 lines (34 loc) · 1.56 KB
/
options-manager.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
function updateDarkMode() {
let invert = enableAlwaysDarkMode || (enableAutoDarkMode && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (invert) document.documentElement.classList.add("bdd-dark");
else document.documentElement.classList.remove("bdd-dark");
}
function updateOptions() {
function setSubpixel(result) {
enableSubpixel = result.subpixel == null ? true : result.subpixel;
// Set all canvases to be opaque. May cause layout issues
var canvases = document.getElementsByTagName('canvas');
for (var i = 0; i < canvases.length; i++) {
if (enableSubpixel) canvases[i].setAttribute("moz-opaque", "true");
}
if (enableSubpixel) document.documentElement.classList.add("bdd-subpixel");
else document.documentElement.classList.remove("bdd-subpixel");
}
function setDarkmode(result) {
let dm = result.darkmode || "auto";
enableAutoDarkMode = dm == "auto";
enableAlwaysDarkMode = dm == "always";
updateDarkMode()
}
let spgetting = browser.storage.sync.get("subpixel");
spgetting.then(setSubpixel, onError);
let dmgetting = browser.storage.sync.get("darkmode");
dmgetting.then(setDarkmode, onError);
}
updateOptions();
function onError(error) {
console.log(`BDD Options Error: ${error}`);
}
browser.storage.onChanged.addListener(updateOptions);
const darkModePreference = window.matchMedia("(prefers-color-scheme: dark)");
darkModePreference.addEventListener("change", e => e.matches && updateDarkMode());