(randomized footers!) |
m (whoops I'm an idiot (ensure tagline is initialized)) |
||
Line 2: | Line 2: | ||
const $$ = x => document.querySelectorAll(x) | const $$ = x => document.querySelectorAll(x) | ||
let tagline = $('[data-footer-tagline]') | let tagline | ||
tagline.addEventListener('click', () => handleTagline()) | window.addEventListener('load', () => { | ||
tagline = $('[data-footer-tagline]') | |||
tagline.addEventListener('click', () => handleTagline()) | |||
handleTagline() | |||
}) | |||
function handleTagline() { | function handleTagline() { | ||
Line 42: | Line 45: | ||
} | } | ||
let chosen = opts[Math.floor(Math.random() * opts.length)] | let chosen = opts[Math.floor(Math.random() * opts.length)] | ||
tagline.textContent = chosen | tagline.textContent = chosen | ||
} | } |
Revision as of 22:18, 29 April 2023
const $ = x => document.querySelector(x)
const $$ = x => document.querySelectorAll(x)
let tagline
window.addEventListener('load', () => {
tagline = $('[data-footer-tagline]')
tagline.addEventListener('click', () => handleTagline())
handleTagline()
})
function handleTagline() {
if (tagline === undefined) {
return
}
let optChs = [...tagline.dataset.footerTagline]
let opts = []
let opt = null
while (optChs.length > 0) {
let ch = optChs.shift()
if (ch === '\\') {
ch = optChs.shift()
} else if (ch === ';') {
opts.push(opt)
opt = null
continue
}
opt ??= ''
opt += ch
}
if (opt !== null) {
opts.push(opt ?? '')
}
opts = opts
.map(i => i.trim())
.filter(i => i !== '')
let oldOpts = opts
opts = opts.filter(i => tagline.textContent !== i)
if (opts.length === 0) {
if (oldOpts.length === 0) {
console.warn('No footer tagline options specified')
} else {
console.warn('All footer tagline options are identical')
}
return
}
let chosen = opts[Math.floor(Math.random() * opts.length)]
tagline.textContent = chosen
}