about summary refs log tree commit diff stats
path: root/src/pages/options/init.js
blob: daea2963b6b45a197b72eb59de6e371a293a27f8 (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
32
33
34
35
36
37
38
window.browser = window.browser || window.chrome;

import localise from "../../assets/javascripts/localise.js";

function changeTheme() {
    return new Promise(resolve => {
        browser.storage.local.get(
            "theme",
            r => {
                switch (r.theme) {
                    case "dark":
                        document.body.classList.add("dark-theme");
                        document.body.classList.remove("light-theme");
                        break;
                    case "light":
                        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");
                        }
                }
                resolve();
            }
        )
    })
}

changeTheme();
if (["ar", "iw", "ku", "fa", "ur"].includes(browser.i18n.getUILanguage())) document.getElementsByTagName("body")[0].classList.add("rtl");
localise.localisePage();

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