2022-03-09 10:23:26 -06:00
|
|
|
const body = document.body
|
|
|
|
const queryAll = sel => document.querySelectorAll(sel)
|
|
|
|
|
2022-05-25 09:48:16 -05:00
|
|
|
const resetTheme = () => {
|
|
|
|
body.classList.remove('dark-theme', 'light-theme')
|
2020-12-15 16:30:13 -06:00
|
|
|
}
|
2022-03-09 10:23:26 -06:00
|
|
|
|
2022-05-25 09:48:16 -05:00
|
|
|
queryAll('.theme-toggler').forEach(a => a.addEventListener('click', () => console.log('yo')))
|
2022-03-09 10:23:26 -06:00
|
|
|
queryAll('.js-only').forEach(a => a.classList.remove('js-only'))
|
|
|
|
queryAll('.js-disabled-only').forEach(a => a.remove())
|
2020-12-15 16:30:13 -06:00
|
|
|
|
|
|
|
const initAlign = () => {
|
2022-03-09 10:23:26 -06:00
|
|
|
const cur = localStorage.getItem('align')
|
|
|
|
const prev = cur == 'center' ? 'left' : 'center'
|
|
|
|
body.classList.add('align-' + cur)
|
|
|
|
body.classList.remove('align-' + prev)
|
2020-12-15 16:30:13 -06:00
|
|
|
}
|
2022-03-09 10:23:26 -06:00
|
|
|
|
|
|
|
if (localStorage.getItem('align') === null) localStorage.setItem('align', 'center')
|
|
|
|
|
2020-12-15 16:30:13 -06:00
|
|
|
initAlign()
|
2022-03-09 10:23:26 -06:00
|
|
|
|
2020-12-15 16:30:13 -06:00
|
|
|
const toggleAlign = ev => {
|
2022-03-09 10:23:26 -06:00
|
|
|
localStorage.setItem('align', localStorage.getItem('align') == 'center' ? 'left' : 'center')
|
2020-12-15 16:30:13 -06:00
|
|
|
initAlign()
|
2022-05-25 09:48:16 -05:00
|
|
|
if (ev.target) ev.preventDefault()
|
2020-12-15 16:30:13 -06:00
|
|
|
return false
|
|
|
|
}
|
2022-03-09 10:23:26 -06:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|