alexohneander-zola/static/js/initialize_theme.js
welpo 9512bbb194
♻️ refactor: use const in theme initialization
Refactor the theme initialization script to use 'const' instead of 'let'
for the 'currentTheme' variable, as the value is not expected to change
after initialization.

This makes the code more clear and prevents accidental
re-assignment.
2023-04-28 16:38:46 +02:00

10 lines
377 B
JavaScript

(function () {
const currentTheme = localStorage.getItem('theme');
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
} else {
const isSystemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
document.documentElement.setAttribute('data-theme', isSystemDark ? 'dark' : 'light');
}
})();