summaryrefslogblamecommitdiff
path: root/reference/js/setTheme.js
blob: 41680b91ddd68cb720a9916b4688bfc574db9614 (plain) (tree)
1
2
3
4
5
6
7
8
9
10







                                                                    

                               

                               


                                            

                                     


                                             




                                 

                                                                      

                                                                      
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   bodyColour;
	var   backgroundColour;
	var   foregroundColour;
	if (theme === "dark") {
		bodyColour       = black;
		backgroundColour = darkgrey;
		foregroundColour = white;
	}
	else if (theme === "light") {
		bodyColour       = lightgrey;
		backgroundColour = white;
		foregroundColour = black;
	}
	else {
		setTheme("dark");
		return;
	}
	root.style.setProperty("--bodyColour",      bodyColour);
	root.style.setProperty("--backgroundColour",backgroundColour);
	root.style.setProperty("--foregroundColour",foregroundColour);
}