InkSoul/public/js/meme.min.908b8d39aabea564ae...

1 line
4.7 KiB
JavaScript

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