InkSoul/public/js/meme.min.ac2b48f322cff6a9a8...

1 line
4.7 KiB
JavaScript

const throttle=(e,t)=>{let s,o,n;return function(){const i=this,a=arguments;s?(clearTimeout(o),o=setTimeout(function(){Date.now()-n>=t&&(e.apply(i,a),n=Date.now())},Math.max(t-(Date.now()-n),0))):(e.apply(i,a),n=Date.now(),s=!0)}},delayTime=420;window.addEventListener("DOMContentLoaded",e=>{const t=document.querySelector(".header");if(t){const e=window.getComputedStyle(t,null).getPropertyValue("height");document.documentElement.style.setProperty("--header-height",e)}},{once:!0}),window.addEventListener("DOMContentLoaded",e=>{const n=document.querySelector(".nav-toggle"),o=document.createElement("div");o.className="nav-toggle-inner",n.appendChild(o);for(let e=0;e<3;e++){const t=document.createElement("span");o.appendChild(t)}const s=document.getElementById("nav-toggle"),t=document.querySelector(".header"),i=document.querySelector(".nav-curtain");s.addEventListener("change",e=>{e.target.checked?(t.classList.add("open"),n.classList.add("open"),t.classList.remove("fade"),i.style="display: block"):(t.classList.remove("open"),n.classList.remove("open"),t.classList.add("fade"))}),i.addEventListener("animationend",e=>{s.checked||e.target.removeAttribute("style")}),window.addEventListener("scroll",throttle(function(){l()},delayTime));const r=window.getComputedStyle(document.documentElement,null).getPropertyValue("--max-width");let c=window.matchMedia(`(max-width: ${r})`);c.addListener(e=>{e.matches||a(!0)});function l(){const e=document.getElementById("search-input");if(e&&e===document.activeElement)return;a()}function a(e){s.checked&&(s.checked=!1,t.classList.remove("open"),n.classList.remove("open"),e?i.removeAttribute("style"):t.classList.add("fade"))}},{once:!0}),window.addEventListener("DOMContentLoaded",e=>{const t=document.getElementById("back-to-top");t!==null&&window.addEventListener("scroll",throttle(function(){window.scrollY>100?t.classList.add("show"):t.classList.remove("show")},delayTime))},{once:!0});const userPrefers=localStorage.getItem("theme");userPrefers==="dark"?changeModeMeta("dark"):userPrefers==="light"&&changeModeMeta("light"),window.matchMedia("(prefers-color-scheme: dark)").addListener(e=>{changeMode()}),window.addEventListener("DOMContentLoaded",e=>{changeMode();const t=document.getElementById("theme-switcher");t&&t.addEventListener("click",e=>{e.preventDefault(),changeModeMeta(getCurrentTheme()=="dark"?"light":"dark"),changeMode(),storePrefers()})},{once:!0}),window.addEventListener("storage",function(e){if(e.key!=="theme")return;changeModeMeta(e.newValue==="dark"?"dark":"light"),changeMode()});function getCurrentTheme(){return JSON.parse(window.getComputedStyle(document.documentElement,null).getPropertyValue("--theme-name"))}function changeModeMeta(e){document.documentElement.setAttribute("data-theme",e)}function changeMode(){const e=getCurrentTheme()==="dark",t=e?"#16171d":"#fff";if(document.querySelector('meta[name="theme-color"]').setAttribute("content",t),typeof mermaidConfig!="undefined"){const t=document.querySelectorAll(".mermaid");t.forEach(e=>{e.getAttribute("data-processed")?(e.removeAttribute("data-processed"),e.innerHTML=e.getAttribute("data-graph")):e.setAttribute("data-graph",e.textContent)}),e?(mermaidConfig.theme="dark",mermaid.initialize(mermaidConfig),mermaid.init()):(mermaidConfig.theme="default",mermaid.initialize(mermaidConfig),mermaid.init())}}function storePrefers(){window.localStorage.setItem("theme",getCurrentTheme())}window.addEventListener("DOMContentLoaded",e=>{const t="复制",o="已复制";var n="https://fastly.jsdelivr.net",i="https://cdn.jsdelivr.net";document.querySelectorAll(".post-body > pre").forEach(e=>{let t=document.createElement("div");e.parentNode.replaceChild(t,e),t.appendChild(e)});function s(e){const n=document.querySelectorAll("table.lntable, .highlight > pre, .post-body > div > pre");n.forEach(n=>{n.parentNode.style.position="relative";const s=document.createElement("button");if(s.className="copy-button",s.type="button",s.innerText=t,n.classList.contains("lntable"))var i=n.querySelectorAll(".lntd")[1];else i=n.querySelector("code");s.addEventListener("click",()=>{e.writeText(i.innerText).then(()=>{s.blur(),s.innerText=o,setTimeout(()=>{s.innerText=t},1e3)}).catch(e=>{s.innerText="Error",console.error(e)})}),n.appendChild(s),n.parentNode.addEventListener("mouseover",()=>{s.style="visibility: visible; opacity: 1"}),n.parentNode.addEventListener("mouseout",()=>{s.style="visibility: hidden; opacity: 0"})})}if(navigator&&navigator.clipboard)s(navigator.clipboard);else{const e=document.createElement("script");(n=null)?e.src=i+"/npm/clipboard-polyfill@2.8.6/dist/clipboard-polyfill.min.js":e.src=n+"/npm/clipboard-polyfill@2.8.6/dist/clipboard-polyfill.min.js",e.defer=!0,e.onload=function(){s(clipboard)},document.head.appendChild(e)}},{once:!0})