FBLA25/static/themeGetter.ts
drake d32a6b412e
Some checks failed
ci / docker_image (push) Failing after 1m4s
ci / deploy (push) Has been skipped
app dev and CI
2024-12-17 19:26:53 -06:00

10 lines
355 B
TypeScript

const saved_theme = localStorage.getItem('theme');
if (saved_theme) {
document.body.setAttribute('data-theme', saved_theme);
} else {
const prefers_dark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = prefers_dark ? 'dark' : 'light';
document.body.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
}