summaryrefslogblamecommitdiff
path: root/reference/js/setTheme.js
blob: b90f6298f8294719a6b0058e0387f2800f50ec2b (plain) (tree)




























                                                                        
function setTheme(theme) {
	localStorage.setItem("theme",theme);
	var   root      = document.querySelector(":root");
	var   rootstyle = getComputedStyle(root);
	const black     = rootstyle.getPropertyValue("--black");
	const darkgrey  = rootstyle.getPropertyValue("--darkgrey");
	const lightgrey = rootstyle.getPropertyValue("--lightgrey");
	const white     = rootstyle.getPropertyValue("--white");
	var   backgroundColour0;
	var   backgroundColour1;
	var   foregroundColour;
	if (theme === "dark") {
		backgroundColour0 = black;
		backgroundColour1 = darkgrey;
		foregroundColour  = white;
	}
	else if (theme === "light") {
		backgroundColour0 = lightgrey;
		backgroundColour1 = white;
		foregroundColour  = black;
	}
	else {
		setTheme("dark");
		return;
	}
	root.style.setProperty("--backgroundColour0",backgroundColour0);
	root.style.setProperty("--backgroundColour1",backgroundColour1);
	root.style.setProperty("--foregroundColour",foregroundColour);
}