-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-schema.js
1 lines (1 loc) · 1.75 KB
/
color-schema.js
1
!function(t,e){var r=e.documentElement;function o(t){try{return localStorage.getItem(t)}catch(t){return null}}function n(){var t=getComputedStyle(r).getPropertyValue("--color-mode");return"string"==typeof t?t.replace(/["'\s]/g,""):null}function a(){r.setAttribute("data-user-color-scheme",l()),function(t){try{localStorage.removeItem(t)}catch(t){}}("Fluid_Color_Scheme")}var c={dark:!0,light:!0};function l(){var t,e="string"==typeof(t=r.getAttribute("data-default-color-scheme"))?t.replace(/["'\s]/g,""):null;if(c[e])return e;if(e=n(),c[e])return e;var o=(new Date).getHours();return o>=18||o>=0&&o<=6?"dark":"light"}function i(n){var i=n||o("Fluid_Color_Scheme")||l();if(i===l())a();else{if(!c[i])return void a();r.setAttribute("data-user-color-scheme",i)}!function(t){if(c[t]){var r="icon-dark";t&&(r="icon-"+u[t]);var o=e.getElementById("color-toggle-icon");o?(o.setAttribute("class","iconfont "+r),o.setAttribute("data",u[t])):waitElementLoaded("color-toggle-icon",(function(){var o=e.getElementById("color-toggle-icon");o&&(o.setAttribute("class","iconfont "+r),o.setAttribute("data",u[t]))}))}}(i),function(r){t.REMARK42&&t.REMARK42.changeTheme(r);var o=e.querySelector("iframe");if(o){var n=t.UtterancesThemeLight;"dark"===r&&(n=t.UtterancesThemeDark);const e={type:"set-theme",theme:n};o.contentWindow.postMessage(e,"https://utteranc.es")}}(i)}var u={dark:"light",light:"dark"};function d(){var t=o("Fluid_Color_Scheme");if(c[t])t=u[t];else{if(null!==t)return;var r=e.getElementById("color-toggle-icon");r&&(t=r.getAttribute("data")),r&&c[t]||(t=u[n()])}return function(t,e){try{localStorage.setItem(t,e)}catch(t){}}("Fluid_Color_Scheme",t),t}i();var g=t.onload;t.onload=function(){g&&g(),e.getElementById("color-toggle-btn").addEventListener("click",()=>{i(d())})}}(window,document);