Created
October 13, 2019 05:14
-
-
Save z-------------/5b396139bbc39ffa18482620a4b9140b 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
const isDarkMode = () => { | |
return window.matchMedia("(prefers-color-scheme: dark)").matches; | |
}; | |
const onThemeChange = (function() { | |
let listeners = []; | |
let mm = window.matchMedia("(prefers-color-scheme: dark)"); | |
mm.addEventListener("change", e => { | |
for (let listener of listeners) { | |
listener(e.matches); | |
} | |
}); | |
return callback => { | |
listeners.push(callback); | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment