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

12 lines
392 B
JavaScript
Raw Normal View History

2024-03-27 21:53:04 -04:00
const preferredMode = window.matchMedia("(prefers-color-scheme: dark)").matches
? "DARK"
: "LIGHT";
2024-03-26 18:00:05 -04:00
// sets theme before rendering & jquery loaded to prevent flashing of uninitialized theme
// (ugly white background)
2024-03-27 22:08:58 -04:00
localStorage.setItem("theme", localStorage.getItem("theme") || preferredMode);
document.documentElement.setAttribute(
"data-theme",
localStorage.getItem("theme"),
);