Files
mathew/lean/theme/theme-init.js
Aran Roig 6df7950161
Some checks failed
Build and Deploy Nuxt / build (push) Failing after 41s
Ai slop
2026-10-03 14:13:08 +02:00

25 lines
1019 B
JavaScript

/* Mathew's theme handshake with the wiki (see mathew.css, its stylesheet).
*
* The wiki opens this frame as ?theme=light|dark — the editor cannot see
* the page around it (another origin), but it can at least open wearing
* the same mood. Without the parameter — a direct visit — the browser's
* preference decides, the same rule lean4web follows for its own default.
*
* Runs synchronously in <head>, before the first paint, so the page never
* flashes the wrong palette; <html data-mathew-theme> is the hook the
* stylesheet's overrides hang on. */
(function () {
var param = null
try {
param = new URLSearchParams(window.location.search).get('theme')
} catch (e) {
/* an engine without URLSearchParams gets the fallback below */
}
var theme = param === 'light' || param === 'dark'
? param
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light'
document.documentElement.setAttribute('data-mathew-theme', theme)
})()