UNPKG

hexo-theme-kratos-rebirth

Version:
2 lines (1 loc) 13.4 kB
(()=>{var oe=s=>typeof s=="object"&&s!=null&&s.nodeType===1,ne=(s,d)=>(!d||s!=="hidden")&&s!=="visible"&&s!=="clip",Z=(s,d)=>{if(s.clientHeight<s.scrollHeight||s.clientWidth<s.scrollWidth){let p=getComputedStyle(s,null);return ne(p.overflowY,d)||ne(p.overflowX,d)||(E=>{let h=(u=>{if(!u.ownerDocument||!u.ownerDocument.defaultView)return null;try{return u.ownerDocument.defaultView.frameElement}catch(v){return null}})(E);return!!h&&(h.clientHeight<E.scrollHeight||h.clientWidth<E.scrollWidth)})(s)}return!1},z=(s,d,p,E,h,u,v,g)=>u<s&&v>d||u>s&&v<d?0:u<=s&&g<=p||v>=d&&g>=p?u-s-E:v>d&&g<p||u<s&&g>p?v-d+h:0,ie=s=>{let d=s.parentElement;return d==null?s.getRootNode().host||null:d},_=(s,d)=>{var p,E,h,u;if(typeof document>"u")return[];let{scrollMode:v,block:g,inline:L,boundary:H,skipOverflowHiddenElements:U}=d,X=typeof H=="function"?H:a=>a!==H;if(!oe(s))throw new TypeError("Invalid target");let q=document.scrollingElement||document.documentElement,D=[],y=s;for(;oe(y)&&X(y);){if(y=ie(y),y===q){D.push(y);break}y!=null&&y===document.body&&Z(y)&&!Z(document.documentElement)||y!=null&&Z(y,U)&&D.push(y)}let k=(E=(p=window.visualViewport)==null?void 0:p.width)!=null?E:innerWidth,N=(u=(h=window.visualViewport)==null?void 0:h.height)!=null?u:innerHeight,{scrollX:x,scrollY:I}=window,{height:S,width:T,top:e,right:t,bottom:o,left:n}=s.getBoundingClientRect(),{top:r,right:f,bottom:C,left:M}=(a=>{let i=window.getComputedStyle(a);return{top:parseFloat(i.scrollMarginTop)||0,right:parseFloat(i.scrollMarginRight)||0,bottom:parseFloat(i.scrollMarginBottom)||0,left:parseFloat(i.scrollMarginLeft)||0}})(s),w=g==="start"||g==="nearest"?e-r:g==="end"?o+C:e+S/2-r+C,l=L==="center"?n+T/2-M+f:L==="end"?t+f:n-M,c=[];for(let a=0;a<D.length;a++){let i=D[a],{height:m,width:b,top:W,right:G,bottom:J,left:F}=i.getBoundingClientRect();if(v==="if-needed"&&e>=0&&n>=0&&o<=N&&t<=k&&e>=W&&o<=J&&n>=F&&t<=G)return c;let O=getComputedStyle(i),R=parseInt(O.borderLeftWidth,10),j=parseInt(O.borderTopWidth,10),Y=parseInt(O.borderRightWidth,10),P=parseInt(O.borderBottomWidth,10),A=0,B=0,$="offsetWidth"in i?i.offsetWidth-i.clientWidth-R-Y:0,V="offsetHeight"in i?i.offsetHeight-i.clientHeight-j-P:0,K="offsetWidth"in i?i.offsetWidth===0?0:b/i.offsetWidth:0,Q="offsetHeight"in i?i.offsetHeight===0?0:m/i.offsetHeight:0;if(q===i)A=g==="start"?w:g==="end"?w-N:g==="nearest"?z(I,I+N,N,j,P,I+w,I+w+S,S):w-N/2,B=L==="start"?l:L==="center"?l-k/2:L==="end"?l-k:z(x,x+k,k,R,Y,x+l,x+l+T,T),A=Math.max(0,A+I),B=Math.max(0,B+x);else{A=g==="start"?w-W-j:g==="end"?w-J+P+V:g==="nearest"?z(W,J,m,j,P+V,w,w+S,S):w-(W+m/2)+V/2,B=L==="start"?l-F-R:L==="center"?l-(F+b/2)+$/2:L==="end"?l-G+Y+$:z(F,G,b,R,Y+$,l,l+T,T);let{scrollLeft:ee,scrollTop:te}=i;A=Q===0?0:Math.max(0,Math.min(te+A/Q,i.scrollHeight-m/Q+V)),B=K===0?0:Math.max(0,Math.min(ee+B/K,i.scrollWidth-b/K+$)),w+=te-A,l+=ee-B}c.push({el:i,top:A,left:B})}return c};var re=s=>s===!1?{block:"end",inline:"nearest"}:(d=>d===Object(d)&&Object.keys(d).length!==0)(s)?s:{block:"start",inline:"nearest"};function se(s,d){if(!s.isConnected||!(h=>{let u=h;for(;u&&u.parentNode;){if(u.parentNode===document)return!0;u=u.parentNode instanceof ShadowRoot?u.parentNode.host:u.parentNode}return!1})(s))return;let p=(h=>{let u=window.getComputedStyle(h);return{top:parseFloat(u.scrollMarginTop)||0,right:parseFloat(u.scrollMarginRight)||0,bottom:parseFloat(u.scrollMarginBottom)||0,left:parseFloat(u.scrollMarginLeft)||0}})(s);if((h=>typeof h=="object"&&typeof h.behavior=="function")(d))return d.behavior(_(s,d));let E=typeof d=="boolean"||d==null?void 0:d.behavior;for(let{el:h,top:u,left:v}of _(s,re(d))){let g=u-p.top+p.bottom,L=v-p.left+p.right;h.scroll({top:g,left:L,behavior:E})}}window.requestIdleCallback=window.requestIdleCallback||function(s){let d=Date.now();return setTimeout(function(){s({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-d))}})},1)};window.cancelIdleCallback=window.cancelIdleCallback||function(s){clearTimeout(s)};(()=>{let s=(e,t)=>{if(t){let o=t.innerText;navigator.clipboard.writeText(o);let n=e.innerHTML;e.innerHTML='<i class="fa fa-check-circle"></i>&nbsp;\u6210\u529F~',setTimeout(()=>{e.innerHTML=n},3e3)}},d=async()=>{var t;let e=(((t=window.kr)==null?void 0:t.siteRoot)||"/")+"config.json";return await fetch(e).then(o=>o.json())},p=()=>{let e=!1,t=()=>{window.requestAnimationFrame(()=>{window.scrollY>200?e||(document.body.classList.add("scroll-down"),e=!0):e&&(document.body.classList.remove("scroll-down"),e=!1)})};document.getElementById("gotop-box").addEventListener("click",o=>(window.scrollTo({top:0,behavior:"smooth"}),!1)),t(),window.addEventListener("scroll",t)},E=()=>{let e=document.getElementById("kratos-menu-wrap").cloneNode(!0);e.setAttribute("id","offcanvas-menu"),e.querySelectorAll("ul").forEach(o=>{o.removeAttribute("id")});let t=document.getElementById("kratos-nav-toggle-wrapper");document.getElementById("kratos-nav-toggle").addEventListener("click",()=>{t.classList.contains("toon")?(t.classList.remove("toon"),e.classList.remove("show")):(t.classList.add("toon"),e.classList.add("show"))}),e.addEventListener("click",o=>{o.target.tagName.toLowerCase()==="a"&&o.target.getAttribute("href")&&(t.classList.remove("toon"),e.classList.remove("show"))}),window.addEventListener("resize",o=>{window.innerWidth>768&&t.classList.contains("toon")&&(t.classList.remove("toon"),e.classList.remove("show"))}),document.getElementById("kratos-page").prepend(e)},h=()=>{document.querySelectorAll(".collapse-box-control").forEach(e=>{var t;(t=e.querySelector(".collapse-box-header"))==null||t.addEventListener("click",o=>{e.classList.toggle("active")})})},u=e=>{if(e.enable){let t=document.getElementsByClassName("kratos-page-content");t.length>0&&new Viewer(t[0],{filter:o=>!(typeof o.closest=="function"&&o.closest(".kr-linklist")!==null)})}},v,g=e=>{v=e.template.replaceAll("$NEWLINE","\n").replaceAll("$AUTHOR",document.querySelector("meta[name='author']").getAttribute("content")).replaceAll("$TITLE",document.title).replaceAll("$LINK",window.location.href)},L=e=>{e.enable&&(document.body.oncopy=t=>{if(v){let o=window.getSelection().toString();o.length>e.threshold&&(t.preventDefault(),t.clipboardData&&t.clipboardData.setData("text/plain",o+v))}})},H=(e,t=!0)=>{let o,n=e/1e3,r=Math.floor(n/60/60/24),f=Math.floor(n/60/60-24*r),C=Math.floor(n/60-24*60*r-60*f),M=Math.floor(n-24*60*60*r-60*60*f-60*C),w=r.toString(),l=f.toString(),c=C.toString(),a=M.toString();return t?(w&&w.length===1&&(w="0"+w),l&&l.length===1&&(l="0"+l),c&&c.length===1&&(c="0"+c),a&&a.length===1&&(a="0"+a),o=w+"\u5929"+l+"\u5C0F\u65F6"+c+"\u5206"+a+"\u79D2"):r<540?r<60?o=w+"\u5929":o=Math.floor(r/30).toString()+"\u4E2A\u6708":o=Math.floor(r/365).toString()+"\u5E74",o},U=e=>{let t=new Date(e.since),o=document.getElementById("kr-since");setInterval(()=>{o.innerText=H(Date.now()-t)},1e3)},X=()=>{document.querySelectorAll("figure.highlight").forEach((o,n)=>{let r=o.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0].getElementsByTagName("tr")[0].getElementsByClassName("code")[0],f=document.createElement("button");f.className="copy-code",f.innerHTML='<i class="fa fa-copy"></i>&nbsp;\u590D\u5236',f.onclick=s.bind(null,f,r),o.appendChild(f)}),document.querySelectorAll("pre:has(code)").forEach((o,n)=>{let r=o.querySelector("code"),f=document.createElement("button");f.className="copy-code",f.innerHTML='<i class="fa fa-copy"></i>&nbsp;\u590D\u5236',f.onclick=s.bind(null,f,r),o.appendChild(f)})},q=()=>{let e=typeof window<"u",t=e&&!("onscroll"in window)||typeof navigator<"u"&&/(gle|ing|ro|msn)bot|crawl|spider|yand|duckgo/i.test(navigator.userAgent),o=e&&"IntersectionObserver"in window,n=document.querySelector(".kr-comments.lazy-load"),r=()=>{window.loadCommentsEventHandler&&window.cancelIdleCallback(window.loadCommentsEventHandler),typeof window.loadComments=="function"&&(window.loadCommentsEventHandler=window.requestIdleCallback(window.loadComments),window.loadComments=null)};if(e&&!t&&o&&n){let f=new IntersectionObserver(C=>{C[0].isIntersecting&&(r(),f.disconnect())},{threshold:0});f.observe(n)}else r();window.addEventListener("pjax:before",()=>{window.loadComments&&(window.loadComments=null)},{once:!0})},D=()=>{let e=document.getElementById("expire-alert");if(e){let t=e.querySelector("time"),o=new Date(parseInt(t.getAttribute("datetime"))),r=Date.now()-o,f=e.getAttribute("data-after-days");r>parseInt(f)*24*3600*1e3&&(t.innerText=H(r,!1),e.classList.remove("hidden"))}},y=()=>{var t;let e=document.getElementsByClassName("kratos-page-content");if(e.length>0){let o=e[0].querySelectorAll("img[alt]");for(let n of o)(t=n.closest)!=null&&t.call(n,".kr-linklist")||(n.classList.add("with-caption"),n.insertAdjacentHTML("afterend",'<span class="img-caption">'.concat(n.getAttribute("alt"),"</span>")))}},k=(e,t)=>{let o=0;return function(){let n=this,r=arguments;clearTimeout(o),o=setTimeout(function(){e.apply(n,r)},t||0)}},N=()=>{let e=document.getElementById("krw-toc"),t=()=>{let o=e.getElementsByClassName("toc-item"),n=[];try{Array.from(o).forEach(l=>{let c=l.querySelector(".toc-link"),a=decodeURI(c.getAttribute("href"));if(a.substring(0,1)!="#")throw new Error("TOC \u5C0F\u6807\u9898\u94FE\u63A5\u65E0\u6548\uFF0C\u683C\u5F0F\u65E0\u9650");let i=document.getElementById(a.substring(1));if(!i)throw new Error("TOC \u5C0F\u6807\u9898\u94FE\u63A5\u65E0\u6548\uFF0C\u672A\u627E\u5230\u76F8\u5173\u5F15\u7528");i.setAttribute("data-toc-id",n.length),n.push({at:i,el:l})})}catch(l){console.log("\u9519\u8BEF\uFF1A",l.message),Array.from(o).forEach(c=>{c.classList.add("show")});return}let r=-1,f=l=>{if(r!==l){if(r!==-1&&n[r]){n[r].el.classList.remove("active"),n[r].el.classList.remove("show");let c=n[r].el;for(;!c.classList.contains("toc");)c.classList.contains("toc-item")&&c.classList.remove("show"),c=c.parentNode}if(l!==-1&&n[l]){n[l].el.classList.add("active"),n[l].el.classList.add("show");let c=n[l].el;for(;!c.classList.contains("toc");)c.classList.contains("toc-item")&&c.classList.add("show"),c=c.parentNode;setTimeout(()=>{var i;let a=(i=n[l])==null?void 0:i.el;a&&se(a,{behavior:"smooth",block:"nearest",inline:"nearest",boundary:e})},300)}r=l}};if("IntersectionObserver"in window){let l=k((a,i)=>{i===window.scrollY?window.requestAnimationFrame(()=>{f(a)}):l(a,window.scrollY)},100),c=new IntersectionObserver(a=>{let i=null;a.forEach(m=>{let b=Number.parseInt(m.target.getAttribute("data-toc-id"),10);m.rootBounds&&(!m.isIntersecting&&m.boundingClientRect.top<=m.rootBounds.top?i=b:m.isIntersecting&&m.boundingClientRect.bottom<m.rootBounds.top+m.rootBounds.height/2&&m.intersectionRatio===1&&(i=b-1))}),i!==null&&l(i,window.scrollY)},{rootMargin:"-62px 0px 0px 0px",threshold:1});n.forEach(a=>{c.observe(a.at)}),window.addEventListener("pjax:before",()=>{c.disconnect(),n.length=0},{once:!0})}else{let l=()=>{n.forEach(m=>{m.h=m.at.getBoundingClientRect().top+window.scrollY-61})};l();let c=()=>{let m;!Number.isInteger(r)||r<0||r>n.length-1?m=0:m=r;let b=window.scrollY;if(b>=n[m].h)if(b>=n[n.length-1].h)m=n.length-1;else for(;b>=n[m+1].h;)m++;else for(;b<n[m].h&&(m--,!(m<0)););return m},a=k(()=>{window.requestAnimationFrame(()=>{f(c())})},100),i=k(()=>{l(),window.requestAnimationFrame(()=>{f(c())})},100);window.addEventListener("resize",i),window.addEventListener("scroll",a),window.addEventListener("pjax:before",()=>{window.removeEventListener("resize",i),window.removeEventListener("scroll",a),n.length=0},{once:!0})}let C=document.getElementsByClassName("toc-progress-bar")[0],M=document.querySelector(".kratos-page-content"),w=()=>{if(M){let l=window.scrollY||document.documentElement.scrollTop,c=M.clientHeight,a=document.documentElement.clientHeight,i=M.offsetTop,m=c>a?c-a:document.documentElement.scrollHeight-a,b=Math.max(0,Math.min((l-i)/m,1)),W=Math.round(b*100);C.style.width=(b*100).toString()+"%",C.setAttribute("aria-valuenow",W)}};window.addEventListener("scroll",()=>{window.requestAnimationFrame(w)}),w()};e&&(e.offsetParent!==null?t():"IntersectionObserver"in window&&new IntersectionObserver(t,{threshold:0,once:!0}).observe(e))},x=e=>{if(!e.enable)return;let t=window.innerHeight,o=!1,n=()=>{window.requestAnimationFrame(()=>{t<window.scrollY?o||(document.body.classList.add("nav-up"),o=!0):t>window.scrollY&&o&&(document.body.classList.remove("nav-up"),o=!1),t=window.scrollY})};window.addEventListener("wheel",n)},I=()=>{let e=[N,X,h,q,D,y];for(let t of e)try{t()}catch(o){console.error("Error: ".concat(o)),o.stack&&console.error(o.stack)}},S=e=>{let t=[()=>g(e.copyrightNoticeForCopy),()=>u(e.viewerjs)];for(let o of t)try{o()}catch(n){console.error("Error: ".concat(n)),n.stack&&console.error(n.stack)}},T=()=>{document.removeEventListener("DOMContentLoaded",T,!1),window.removeEventListener("load",T,!1),d().then(t=>{let o=[()=>L(t.copyrightNoticeForCopy),()=>U(t.uptime),()=>x(t.topNavScrollToggle),()=>S(t)];for(let n of o)try{n()}catch(r){console.error("Error: ".concat(r)),r.stack&&console.error(r.stack)}window.addEventListener("pjax:complete",()=>{S(t)})}).catch(t=>{console.error("Load config failed: ".concat(t))});let e=[p,E,I];for(let t of e)try{t()}catch(o){console.error("Error: ".concat(o)),o.stack&&console.error(o.stack)}window.addEventListener("pjax:complete",()=>{I()})};document.readyState==="complete"?setTimeout(T):(document.addEventListener("DOMContentLoaded",T,!1),window.addEventListener("load",T,!1))})();})();