mirror of
https://github.com/jakejarvis/dark-mode-example.git
synced 2026-09-11 23:25:34 -04:00
Create dark-mode.min.js
This commit is contained in:
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! Dark mode switcheroo | MIT License | jrvs.io/bWMz */
|
||||
(function(){var e=window,t=e.document,i=t.body.classList,a=localStorage,r="dark_mode_pref",c="true",d="false",o=a.getItem(r),s=!1,n="light",m="dark",l=function(){i.remove(n);i.add(m);s=!0},f=function(){i.remove(m);i.add(n);s=!1};o===c&&l();o===d&&f();if(!o){var h="(prefers-color-scheme: dark)",u="(prefers-color-scheme: light)";e.matchMedia(h).matches?l():f();e.matchMedia(h).addListener((function(e){e.matches&&l()}));e.matchMedia(u).addListener((function(e){e.matches&&f()}))}var v=t.querySelector(".dark-mode-toggle");if(v){v.style.visibility="visible";v.addEventListener("click",(function(){if(s){f();a.setItem(r,d)}else{l();a.setItem(r,c)}}),!0)}})();
|
||||
Reference in New Issue
Block a user