MediaWiki:Common.js: Difference between revisions

Added dark mode toggle v1
(Taking another crack at this)
(Added dark mode toggle v1)
Line 549: Line 549:
     $(window).resize(setStickyHeaderTop);
     $(window).resize(setStickyHeaderTop);
   }
   }
}
function setItem(key, value) {
localStorage.setItem(key, JSON.stringify(value));
}
function getItem(key) {
let keydata = localStorage.getItem(key);
if (keydata == "undefined") return undefined;
return JSON.parse(keydata);
}
function toggleDarkMode() {
const darkMode = getItem("darkMode");
if (darkMode !== true) {
  setItem("darkMode", true);
  document.body.classList.add("darkMode");
}
else {
  setItem("darkMode", false);
  document.body.classList.remove("darkMode");
}
}
}
);
);