mirror of
https://github.com/netz39/www.netz39.de.git
synced 2025-01-18 20:10:12 +01:00
Fix auto darkmode is overwritten by light mode
This commit is contained in:
parent
665949d7c1
commit
7c4b2b77d7
2 changed files with 2 additions and 1 deletions
2
assets/js/main.min.js
vendored
2
assets/js/main.min.js
vendored
|
@ -1,5 +1,5 @@
|
|||
/* @preserve Cookie Consent Init */
|
||||
function createCookie(e,t,o){var n="";if(o){var i=new Date;i.setTime(i.getTime()+24*o*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=`${e}=${t}${n}; path=/`}function readCookie(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var i=o[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return i.substring(t.length,i.length)}return null}function addCookieConsentListener(){document.getElementById("cookie-notice-accept").addEventListener("click",(function(){createCookie(cookieName,"true",31),document.getElementById("cookie-notice").style.display="none",location.reload()}))}function googleAnalytics(){if(""!==analyticsName.toLowerCase()){function e(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],e("js",new Date),e("config",analyticsName,{anonymize_ip:!0}),analyticsNameGA4&&e("config",analyticsNameGA4,{anonymize_ip:!0})}}"true"===isCookieConsent.toLowerCase()?(addCookieConsentListener(),"true"===readCookie(cookieName)?googleAnalytics():document.getElementById("cookie-notice").style.display="block"):googleAnalytics()
|
||||
/* @preserve Dark mode Init */;const themeButton={light:'<i class="fas fa-adjust" aria-hidden="true"></i>',dark:'<i class="fas fa-adjust fa-rotate-180" aria-hidden="true"></i>'},currentTheme=()=>sessionStorage.getItem("theme");function setMode(e){document.documentElement.setAttribute("data-theme",e),sessionStorage.setItem("theme",e);const t=document.getElementById("theme-toggle");t&&(t.innerHTML=themeButton[e])}function themeToggle(){setMode("light"===currentTheme()?"dark":"light")}window.onload=function(){if(isAutoTheme){if(!currentTheme()){let e=window.matchMedia("(prefers-color-scheme: dark)");e.addEventListener("change",(()=>{e.matches&&sessionStorage.setItem("theme","dark")}))}let e=currentTheme();setMode(e||"light")}}
|
||||
/* @preserve Dark mode Init */;const themeButton={light:'<i class="fas fa-adjust" aria-hidden="true"></i>',dark:'<i class="fas fa-adjust fa-rotate-180" aria-hidden="true"></i>'},currentTheme=()=>sessionStorage.getItem("theme");function setMode(e){document.documentElement.setAttribute("data-theme",e),sessionStorage.setItem("theme",e);const t=document.getElementById("theme-toggle");t&&(t.innerHTML=themeButton[e])}function themeToggle(){setMode("light"===currentTheme()?"dark":"light")}window.onload=function(){if(isAutoTheme){if(!currentTheme()){let e=window.matchMedia("(prefers-color-scheme: dark)");if(e.matches){sessionStorage.setItem("theme","dark");} e.addEventListener("change",(()=>{e.matches&&sessionStorage.setItem("theme","dark")}))}let e=currentTheme();setMode(e||"light")}}
|
||||
/* @preserve Masonry Init */;try{var elem=document.querySelector(".grid"),msnry=new Masonry(elem,{itemSelector:".grid-item",columnWidth:".grid-sizer",gutter:".gutter-sizer",percentPosition:!0}),imgLoad=imagesLoaded(elem);imgLoad.on("progress",(function(e,t){msnry.layout()}))}catch(e){if(!(e instanceof ReferenceError))throw e}
|
||||
/* @preserve Navbar */document.addEventListener("DOMContentLoaded",(function(e){const t=document.getElementById("pull"),o=document.querySelector("nav ul");["click","touch"].forEach((function(e){t?.addEventListener(e,(function(){o.classList.toggle("hide")}),!1)})),window.addEventListener("scroll",(function(){const e=-(window.scrollY||window.pageYOffset||document.body.scrollTop)/3,t=document.getElementById("main");t&&(t.style.backgroundPosition="100% "+(e-50)+"px, 0%, center top")}))}));
|
|
@ -35,6 +35,7 @@ window.onload = function bootstrapTheme() {
|
|||
if (!currentTheme()) {
|
||||
// Load browser's preference
|
||||
let browserPrefersDark = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
if (browserPrefersDark.matches) sessionStorage.setItem('theme', 'dark');
|
||||
browserPrefersDark.addEventListener('change', () => {
|
||||
if (browserPrefersDark.matches) sessionStorage.setItem('theme', 'dark')
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue