const body = document.body const queryAll = sel => document.querySelectorAll(sel) const resetTheme = () => { body.classList.remove('dark-theme', 'light-theme') } queryAll('.theme-toggler').forEach(a => a.addEventListener('click', () => console.log('yo'))) queryAll('.js-only').forEach(a => a.classList.remove('js-only')) queryAll('.js-disabled-only').forEach(a => a.remove()) const initAlign = () => { const cur = localStorage.getItem('align') const prev = cur == 'center' ? 'left' : 'center' body.classList.add('align-' + cur) body.classList.remove('align-' + prev) } if (localStorage.getItem('align') === null) localStorage.setItem('align', 'center') initAlign() const toggleAlign = ev => { localStorage.setItem('align', localStorage.getItem('align') == 'center' ? 'left' : 'center') initAlign() if (ev.target) ev.preventDefault() return false } queryAll('.align-toggler').forEach(a => a.addEventListener('click', toggleAlign)) window.addEventListener('load', _ev => { const selector = [1, 2, 3, 4, 5, 6].map(n => `h${n}[id]`).join(',') queryAll(selector).forEach(el => { const anchorLink = document.createElement('a') anchorLink.classList.add('anchor-link') anchorLink.textContent = 'ยง' anchorLink.href = `#${el.id}` el.appendChild(anchorLink) }) })