aboutsummaryrefslogtreecommitdiff
path: root/static/js/themes.js
blob: 0d9772fcbcc4f4ffc3d7198508d05dc4fa536044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function setCookie(key, value, age) {
	document.cookie = key + "=" + encodeURIComponent(value) + ";sameSite=strict;max-age=" + 60 * 60 * 24 * age + ";path=/";
}

function getCookie(key) {
	if (document.cookie.length != 0) {
		return document.cookie.split('; ').find(row => row.startsWith(key)).split('=')[1];
	}
	return "";
}

function setTheme(name) {
	for (let i = 0, tags = document.getElementsByTagName("link"); i < tags.length; i++) {
		if (tags[i].type === "text/css" && tags[i].title) {
			tags[i].disabled = !(tags[i].title === name);
		}
	}

	setCookie("theme", name, 3650);
}

function applyTheme() {
	setTheme(getCookie("theme") || "default");
}