Skip to content

Commit

Permalink
fix(core): 馃悰 default to auto theme unless set
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair3149 committed Jan 21, 2023
1 parent 8cd462b commit a7406d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion includes/Hooks/SkinHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function onBeforePageDisplay( $out, $skin ): void {
$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

Expand Down
7 changes: 3 additions & 4 deletions resources/skins.citizen.scripts/inline.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
* Citizen
* Inline script used in includes/Hooks/SkinHooks.php
*
* https://starcitizen.tools
*
* Inline script used in includes/Hooks/SkinHooks.php
* Mangle using https://jscompress.com/
*/
window.applyPref = () => {
Expand All @@ -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 = {
Expand Down

0 comments on commit a7406d8

Please sign in to comment.