blob: f88c9ef92b64c3a241e7f350dcc8d3267a09b344 (
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
window.browser = window.browser || window.chrome
import localise from "../../assets/javascripts/localise.js"
import utils from "../../assets/javascripts/utils.js"
import servicesHelper from "../../assets/javascripts/services.js"
if (!(await utils.getOptions())) {
await servicesHelper.initDefaults()
}
function changeTheme() {
return new Promise(async resolve => {
switch ((await utils.getOptions()).theme) {
case "dark":
document.body.classList.add("dark-theme")
document.body.classList.remove("light-theme")
for (const element of document.body.getElementsByClassName('dark')) {
element.style.display = 'none';
}
break
case "light":
document.body.classList.add("light-theme")
document.body.classList.remove("dark-theme")
for (const element of document.body.getElementsByClassName('light')) {
element.style.display = 'none';
}
break
default:
if (matchMedia("(prefers-color-scheme: light)").matches) {
document.body.classList.add("light-theme")
document.body.classList.remove("dark-theme")
for (const element of document.body.getElementsByClassName('light')) {
element.style.display = 'none';
}
} else {
document.body.classList.add("dark-theme")
document.body.classList.remove("light-theme")
for (const element of document.body.getElementsByClassName('dark')) {
element.style.display = 'none';
}
}
}
resolve()
})
}
changeTheme()
if (["ar", "iw", "ku", "fa", "ur"].includes(browser.i18n.getUILanguage())) {
document.getElementsByTagName("body")[0].classList.add("rtl")
document.getElementsByTagName("body")[0].dir = "rtl"
}
localise.localisePage()
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", changeTheme)
|