summaryrefslogtreecommitdiff
path: root/js/setTheme.ts
blob: 25debbabb7e12fdf35abc2697d3d348649db16e7 (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
enum Theme {
	Light,
	Dark,
}

function setTheme(theme: Theme) {
	let is_valid_theme =
		theme == Theme.Light
		|| theme == Theme.Dark;

	if (!is_valid_theme) {
		console.log("invalid theme \"" + theme + "\"");

		// Use default:
		theme = Theme.Dark;
	}

	console.log("setting theme to `" + Theme[theme] + "`");

	let body = document.getElementById("body")!;
	body.setAttribute("data-theme", Theme[theme]);

	localStorage.setItem("theme", JSON.stringify(theme));
}