Created
May 19, 2020 14:05
-
-
Save zidell/717247167bd4f2e1b0532d9a1443d346 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function userTheme() { | |
| window.__THEME_MODE = 'light'; | |
| if (!!window.matchMedia) { | |
| window.__THEME_MODE = window.matchMedia("(prefers-color-scheme: dark)").matches ? 'dark' : 'auto'; | |
| } | |
| document.getElementsByTagName('html')[0].classList[window.__THEME_MODE === 'dark' ? 'add' : 'remove']('darkmode'); | |
| } | |
| if (!!window.matchMedia) { | |
| ['light', 'dark'].forEach(mode => { | |
| window.matchMedia(`(prefers-color-scheme: ${mode})`).addListener(e => { | |
| if(!!e.matches) { | |
| userTheme(); | |
| } | |
| }); | |
| }); | |
| } | |
| userTheme(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment