Add eventlistener for change of day/night mode

And add a static js folder for js-files apart from the asset pipeline.
This commit is contained in:
Thelonius Kort
2023-02-05 20:14:06 +01:00
parent ab2e8ae816
commit ba2949a3bd
6 changed files with 15 additions and 19 deletions

View File

@ -0,0 +1,10 @@
function set_day_night_mode(){
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
}
set_day_night_mode()
matchMedia('(prefers-color-scheme: dark)').addEventListener("change", set_day_night_mode)