-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathdark-mode-switch.min.js
More file actions
6 lines (6 loc) · 902 Bytes
/
dark-mode-switch.min.js
File metadata and controls
6 lines (6 loc) · 902 Bytes
1
2
3
4
5
6
/*!
* Dark Mode Switch v1.0.1 (https://github.com/coliff/dark-mode-switch)
* Copyright 2021 C.Oliff
* Licensed under MIT (https://github.com/coliff/dark-mode-switch/blob/main/LICENSE)
*/
"use strict";var darkSwitch=document.getElementById("darkSwitch");window.addEventListener("load",function(){if(darkSwitch){initTheme();darkSwitch.addEventListener("change",function(){resetTheme()})}});function initTheme(){var darkThemeSelected=localStorage.getItem("darkSwitch")!==null&&localStorage.getItem("darkSwitch")==="dark";darkSwitch.checked=darkThemeSelected;if(darkThemeSelected){document.body.setAttribute("data-theme","dark")}else{document.body.removeAttribute("data-theme")}}function resetTheme(){if(darkSwitch.checked){document.body.setAttribute("data-theme","dark");localStorage.setItem("darkSwitch","dark")}else{document.body.removeAttribute("data-theme");localStorage.removeItem("darkSwitch")}}