15 lines
606 B
JavaScript
15 lines
606 B
JavaScript
(function(){
|
|
var d=document.documentElement,stored=localStorage.getItem('hermes-theme');
|
|
var params=new URLSearchParams(location.search);
|
|
var force=params.get('theme')||stored||'light';
|
|
function apply(){if(d.getAttribute('data-theme')!==force)d.setAttribute('data-theme',force);}
|
|
apply();
|
|
new MutationObserver(function(m){m.forEach(function(x){if(x.attributeName==='data-theme')apply();})}).observe(d,{attributes:true});
|
|
setInterval(apply,300);
|
|
window._toggleTheme=function(){
|
|
force=force==='dark'?'light':'dark';
|
|
localStorage.setItem('hermes-theme',force);
|
|
apply();
|
|
};
|
|
})();
|