hatecomputers.club/static/js/util/setThemeBeforeRender.js

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"),
);