about summary refs log tree commit diff stats
path: root/src/pages/options/init.js
blob: cabef5b27f05315a47dade35d7f5ead585694f5c (plain) (blame)
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
window.browser = window.browser || window.chrome;

function changeTheme() {
    browser.storage.sync.get("theme", (result) => {
        switch (result.theme) {
            case "dark-theme":
                document.body.classList.add("dark-theme");
                document.body.classList.remove("light-theme");
                break;
            case "light-theme":
                document.body.classList.add("light-theme");
                document.body.classList.remove("dark-theme");
                break;
            default:
                if (matchMedia("(prefers-color-scheme: light)").matches) {
                    document.body.classList.add("light-theme");
                    document.body.classList.remove("dark-theme");
                } else {
                    document.body.classList.add("dark-theme");
                    document.body.classList.remove("light-theme");
                }

        }
    })
}

changeTheme()

browser.storage.onChanged.addListener(changeTheme)

window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", changeTheme)