Advertisement
nrzmalik

Storyline Dark and Light Theme Sync

Aug 30th, 2023 (edited)
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.49 KB | Source Code | 0 0
  1. const themeLink = document.createElement("link");
  2.     themeLink.setAttribute("rel", "stylesheet");
  3.     themeLink.setAttribute("id", "theme-stylesheet");
  4.     document.body.appendChild(themeLink);
  5.     const setTheme = () => {
  6.         const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
  7.         themeLink.href = prefersDark ? "dark.css" : "light.css";
  8.     };
  9.     setTheme();
  10.     window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", setTheme);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement