sourcehypertextpubliccodexcodex-themer.js

const codex = {
	switch: function (name, value) {
		localStorage.setItem(name, value);
		if (value != "default") {
			$("html").setAttribute(name, value);
		} else if ($("html").hasAttribute(name)) {
			$("html").removeAttribute(name);
		}

		if (name == "codex-type") {
			if (value == "garamond" || !value) {
				for (let el of $$(":is(h1, h2, h3)[data-fraktur]")) {
					el.innerHTML = el.dataset.fraktur
				}
			} else {
				for (let el of $$(":is(h1, h2, h3)[data-antiqua]")) {
					el.innerHTML = el.dataset.antiqua
				}
			}
		}

		if ($(`#${name}`)) {
			$(`#${name} button[selector-status="enabled"]`).setAttribute(
				"selector-status",
				"disabled"
			);
			$(`button[selector-title="${value}"]`).setAttribute(
				"selector-status",
				"enabled"
			);
		}
	}
};

document.addEventListener("DOMContentLoaded", function () {
	const codexOptions = ["codex-type", "codex-theme", "codex-background"];
	for (let x of codexOptions) {
		if (localStorage[x]) {
			codex.switch(x, localStorage[x]);
		}
	}
});