Advertisement
nrzmalik

Storyline Dark and Light Theme Sync

Aug 30th, 2023
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.67 KB | Source Code | 0 0
  1. var existingLink = document.querySelector('link[href="html5/data/css/output.min.css"][data-noprefix]');
  2. if (existingLink) {
  3.     existingLink.setAttribute("id", "theme-stylesheet");
  4. }
  5.   function setTheme() {
  6.             const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
  7.             const themeLink = document.getElementById("theme-stylesheet");
  8.            
  9.             if (prefersDark) {
  10.                 themeLink.href = "dark.css";
  11.             } else {
  12.                 themeLink.href = "light.css";
  13.             }
  14.         }
  15.  
  16.         setTheme();
  17.         window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", setTheme);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement