tarakan/assets/js/theme.js
Maxfield Luke af6077b9c3
All checks were successful
CI and deploy / Test (push) Successful in 4m52s
CI and deploy / Deploy production (push) Successful in 23s
Initial commit on Forgejo
Fresh repository history for elektrine/tarakan hosted at
https://git.elektrine.com/elektrine/tarakan.
2026-07-29 04:43:40 -04:00

21 lines
931 B
JavaScript

// Runs blocking in <head>, before the first paint.
//
// app.js is a deferred module, so anything it does happens after the browser
// has already drawn the page - which is why the theme toggle used to flash the
// wrong option on load, and why a manually chosen theme would show a frame of
// the OS one first. This has to stay a classic script with no defer/async, and
// it has to stay small enough that blocking on it is free.
//
// Absent attribute means "follow the OS", so the only work here is restoring a
// manual choice. Everything else - the pressed styling, the toggle handlers -
// is CSS and app.js respectively.
(function () {
try {
var theme = localStorage.getItem("tarakan:theme")
if (theme === "light" || theme === "dark") {
document.documentElement.setAttribute("data-theme", theme)
}
} catch (_error) {
// Private mode or blocked storage: fall through to the OS preference.
}
})()