Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const themeLink = document.createElement("link");
- themeLink.setAttribute("rel", "stylesheet");
- themeLink.setAttribute("id", "theme-stylesheet");
- document.body.appendChild(themeLink);
- const setTheme = () => {
- const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
- themeLink.href = prefersDark ? "dark.css" : "light.css";
- };
- setTheme();
- window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", setTheme);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement