not-matthias / apollo

Modern and minimalistic blog theme.
https://not-matthias.github.io/apollo
MIT License
121 stars 70 forks source link

Improvement suggestion to `themetoggle.js` - don't default to light #26

Closed jmetz closed 12 months ago

jmetz commented 1 year ago

For my purposes I created a new version of the themetoggle.js which defaults to the auto value.

Basically the same as before except:

var currentTheme = localStorage.getItem("theme-storage");
if(!currentTheme){
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        currentTheme = "dark";
    } else {
        currentTheme = "light";
    }
}
setTheme(currentTheme);

ie. don't default to light.

I'm sure the above is a bit clunky and can be refined, but it gets the job done!

not-matthias commented 12 months ago

Thanks for reporting!