Rustelo/templates/shared/public/scripts/theme-init.js
2026-07-18 19:57:03 +01:00

17 lines
669 B
JavaScript

// Theme initialization script to prevent flash. Inlined into the shell <head>
// before first paint. Provenance: promoted from jpl-website/site/public/js.
(function() {
const getThemeFromCookie = () => {
const matches = document.cookie.match(/theme=([^;]+)/);
return matches ? matches[1] : null;
};
const theme = getThemeFromCookie() || 'dark';
const html = document.documentElement;
if (theme === 'dark' || (theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
html.classList.add('dark');
html.classList.remove('light');
} else {
html.classList.add('light');
html.classList.remove('dark');
}
})();