u.twoha.cc/static/theme.js
2024-09-13 19:49:18 -05:00

16 lines
611 B
JavaScript

const id = document.getElementById.bind(document);
const theme = id('theme');
const labels = document.querySelectorAll('.fa,.a');
const dark = id('ldark');
const light = id('llight');
['theme', 'huer', 'hueg', 'hueb'].forEach(e => {
if (localStorage.getItem(e)) { id(e).checked = localStorage.getItem(e) === 'true'; }
id(e).onchange = x => { localStorage.setItem(e, x.target.checked); }
})
labels.forEach(l => l.onkeyup = e => {
if (e.key !== 'Enter') return;
e.target.control.checked = !e.target.control.checked;
if (e.target === dark) light.focus();
else if (e.target === light) dark.focus();
});