Files
website-v2/static/js/DetectMode.js
Greg Newman ed2351a4e4 🐛 Fixes dark mode for charts and search
This problem only seemed to be an issue in Firefox so adding an explicity setting if matchMedia finds dark.

Issue: #729
2023-10-27 09:39:01 -04:00

17 lines
710 B
JavaScript

let explicitelyPreferScheme = false;
if (window.localStorage) {
if (localStorage.getItem('colorMode') === 'dark') {
document.documentElement.classList.add('dark');
explicitelyPreferScheme = 'dark';
} else if (localStorage.getItem('colorMode') === 'light') {
document.documentElement.classList.remove('dark');
explicitelyPreferScheme = 'light';
}
}
if (explicitelyPreferScheme !== 'light' && window.matchMedia('(prefers-color-scheme:dark)').matches) {
localStorage.colorMode = 'dark'; // explicitly set `colorMode` to system if there is no preference. this fixes charts and search default mode in Firefox.
document.documentElement.classList.add('dark');
}