summaryrefslogtreecommitdiff
path: root/app.js
blob: 122cad7c0653314252a8c819e19ea3a180bf2b3b (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
25
26
console.log('Hello from app.js!');

const toggleTheme = function() {
	document.documentElement.style.setProperty(this.id, Number(this.checked));
	localStorage.setItem(this.id, Number(this.checked));
};

const initInput = function(styleVariable=null) {
	let initValue = localStorage.getItem(styleVariable);
	if (initValue) {
		initValue = Number(initValue);
		document.documentElement.style.setProperty(styleVariable, initValue);
	} else {
		initValue = getComputedStyle(document.body).getPropertyValue(styleVariable);
	};

	const inputObject = document.getElementById(styleVariable);
	if (inputObject) {
		inputObject.addEventListener('change', toggleTheme);
		if (inputObject.type == 'checkbox') {
			inputObject.checked = initValue
		};
	};
};

initInput('--dark-theme-check');