Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created October 13, 2019 05:14
Show Gist options
  • Save z-------------/5b396139bbc39ffa18482620a4b9140b to your computer and use it in GitHub Desktop.
Save z-------------/5b396139bbc39ffa18482620a4b9140b to your computer and use it in GitHub Desktop.
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