mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-09-23 18:28:58 +00:00
fix(core): 🐛 default to auto theme unless set
This commit is contained in:
parent
8cd462b731
commit
a7406d8e32
|
@ -62,7 +62,7 @@ class SkinHooks implements
|
|||
$script = sprintf(
|
||||
'<script%s>%s</script>',
|
||||
$nonce !== false ? sprintf( ' nonce="%s"', $nonce ) : '',
|
||||
'window.applyPref=()=>{const a="skin-citizen-",b="skin-citizen-theme",c=a=>window.localStorage.getItem(a),d=c("skin-citizen-theme"),e=()=>{const d={fontsize:"font-size",pagewidth:"--width-layout",lineheight:"--line-height"},e=()=>["auto","dark","light"].map(b=>a+b),f=a=>{let b=document.getElementById("citizen-style");null===b&&(b=document.createElement("style"),b.setAttribute("id","citizen-style"),document.head.appendChild(b)),b.textContent=`:root{${a}}`};try{const g=c(b);let h="";if(null!==g){const b=document.documentElement;b.classList.remove(...e(a)),b.classList.add(a+g)}for(const[b,e]of Object.entries(d)){const d=c(a+b);null!==d&&(h+=`${e}:${d};`)}h&&f(h)}catch(a){}};if("auto"===d){const a=window.matchMedia("(prefers-color-scheme: dark)"),c=a.matches?"dark":"light",d=(a,b)=>window.localStorage.setItem(a,b);d(b,c),e(),a.addEventListener("change",()=>{e()}),d(b,"auto")}else e()},(()=>{window.applyPref()})();'
|
||||
'window.applyPref=()=>{const a="skin-citizen-",b="skin-citizen-theme",c=a=>window.localStorage.getItem(a),d=c("skin-citizen-theme")??"auto",e=()=>{const d={fontsize:"font-size",pagewidth:"--width-layout",lineheight:"--line-height"},e=()=>["auto","dark","light"].map(b=>a+b),f=a=>{let b=document.getElementById("citizen-style");null===b&&(b=document.createElement("style"),b.setAttribute("id","citizen-style"),document.head.appendChild(b)),b.textContent=`:root{${a}}`};try{const g=c(b);let h="";if(null!==g){const b=document.documentElement;b.classList.remove(...e(a)),b.classList.add(a+g)}for(const[b,e]of Object.entries(d)){const d=c(a+b);null!==d&&(h+=`${e}:${d};`)}h&&f(h)}catch(a){}};if("auto"===d){const a=window.matchMedia("(prefers-color-scheme: dark)"),c=a.matches?"dark":"light",d=(a,b)=>window.localStorage.setItem(a,b);d(b,c),e(),a.addEventListener("change",()=>{e()}),d(b,"auto")}else e()},(()=>{window.applyPref()})();'
|
||||
);
|
||||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
/*
|
||||
* Citizen
|
||||
*
|
||||
* Inline script used in includes/Hooks/SkinHooks.php
|
||||
*
|
||||
* https://starcitizen.tools
|
||||
*
|
||||
* Mangle using https://jscompress.com/
|
||||
*/
|
||||
window.applyPref = () => {
|
||||
|
@ -15,7 +13,8 @@ window.applyPref = () => {
|
|||
return window.localStorage.getItem( key );
|
||||
};
|
||||
|
||||
const targetTheme = getStorage( themeKey );
|
||||
// Default to auto if no key is present
|
||||
const targetTheme = getStorage( themeKey ) ?? 'auto';
|
||||
|
||||
const apply = () => {
|
||||
const cssProps = {
|
||||
|
|
Loading…
Reference in a new issue