summaryrefslogtreecommitdiff
path: root/js/setTheme.js
blob: 31cf807b221e5709bd81159bc76adb55d56cb351 (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
function setTheme(theme) {
	localStorage.setItem("theme",theme);
	var   root      = document.querySelector(":root");
	var   rootstyle = getComputedStyle(root);
	const black     = rootstyle.getPropertyValue("--black");
	const white     = rootstyle.getPropertyValue("--white");
	var   bgcol;
	var   fgcol;
	if (theme === "dark") {
		bgcol = black;
		fgcol = white;
	}
	else if (theme === "light") {
		bgcol = white;
		fgcol = black;
	}
	else {
		setTheme("dark");
		return;
	}
	root.style.setProperty("--backgroundColour",bgcol);
	root.style.setProperty("--foregroundColour",fgcol);
}