-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
46 lines (31 loc) · 1.2 KB
/
Copy pathbackground.js
File metadata and controls
46 lines (31 loc) · 1.2 KB
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
// License GPLv3 - https://www.gnu.org/licenses/gpl-3.0.txt
const ICON_PATHS = {
active: { "32": "icons/unicorn-32.png" },
inactive: { "32": "icons/horse-32.png" }
};
async function toggleColors() {
const settings = await browser.browserSettings.overrideDocumentColors.get({});
const nextValue = (settings.value === "always") ? "never" : "always";
await browser.browserSettings.overrideDocumentColors.set({ value: nextValue });
updateIcon(nextValue)
}
function updateIcon(colorSettingsValue) {
const path = (colorSettingsValue === "always")
? ICON_PATHS.active
: ICON_PATHS.inactive;
browser.action.setIcon({ path });
}
// Init
browser.browserSettings.overrideDocumentColors.get({}).then((settings) => {
updateIcon(settings.value);
});
// Listen to changes
browser.action.onClicked.addListener(toggleColors);
browser.tabs.onActivated.addListener(async () => {
const settings = await browser.browserSettings.overrideDocumentColors.get({});
updateIcon(settings.value);
});
browser.windows.onFocusChanged.addListener(async () => {
const settings = await browser.browserSettings.overrideDocumentColors.get({});
updateIcon(settings.value);
});