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

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

function changeTheme() {
	return new Promise(resolve => {
		browser.storage.local.get("options", r => {
			switch (r.options.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)