phoneof/static/js/util/setThemeBeforeRender.js
Elizabeth Hunt f163a24279
All checks were successful
continuous-integration/drone/push Build is passing
initial commit
2025-01-03 01:47:07 -08:00

12 lines
392 B
JavaScript

const preferredMode = window.matchMedia("(prefers-color-scheme: dark)").matches
? "DARK"
: "LIGHT";
// sets theme before rendering & jquery loaded to prevent flashing of uninitialized theme
// (ugly white background)
localStorage.setItem("theme", localStorage.getItem("theme") || preferredMode);
document.documentElement.setAttribute(
"data-theme",
localStorage.getItem("theme"),
);