This commit is contained in:
24
lean/theme/theme-init.js
Normal file
24
lean/theme/theme-init.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/* 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)
|
||||
})()
|
||||
Reference in New Issue
Block a user