Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Automatic system color them #3

Open
morfyum opened this issue Nov 5, 2023 · 1 comment
Open

Feature Request: Automatic system color them #3

morfyum opened this issue Nov 5, 2023 · 1 comment

Comments

@morfyum
Copy link
Owner

morfyum commented Nov 5, 2023

Example code for recognize system-theme

SRC: https://stackoverflow.com/questions/56393880/how-do-i-detect-dark-mode-using-javascript

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    console.log("Dark")
} 
else {
    console.log("Light")
}
// With event listener:
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
    var theme = event.matches ? "dark" : "light";
});
@morfyum
Copy link
Owner Author

morfyum commented Nov 5, 2023

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
    var theme = event.matches ? "dark" : "light";
    document.documentElement.className = theme
    localStorage.setItem("theme", theme);
    //theme = localStorage.getItem("theme");
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant