hexo-theme-kratos-rebirth
Version:
A transplanted theme for Hexo, with many new features built with love.
3 lines (2 loc) • 19.3 kB
JavaScript
;function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function _regeneratorRuntime(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */_regeneratorRuntime=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,r=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function l(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,n){return t[e]=n}}function u(t,e,n,o){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),c=new q(o||[]);return r(i,"_invoke",{value:T(t,n,c)}),i}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var f="suspendedStart",h="suspendedYield",m="executing",p="completed",v={};function g(){}function y(){}function w(){}var b={};l(b,i,(function(){return this}));var x=Object.getPrototypeOf,L=x&&x(x(I([])));L&&L!==n&&o.call(L,i)&&(b=L);var E=w.prototype=g.prototype=Object.create(b);function $(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function C(t,e){function n(r,a,i,c){var s=d(t[r],t,a);if("throw"!==s.type){var l=s.arg,u=l.value;return u&&"object"==_typeof(u)&&o.call(u,"__await")?e.resolve(u.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(u).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}var a;r(this,"_invoke",{value:function(t,o){function r(){return new e((function(e,r){n(t,o,e,r)}))}return a=a?a.then(r,r):r()}})}function T(e,n,o){var r=f;return function(a,i){if(r===m)throw new Error("Generator is already running");if(r===p){if("throw"===a)throw i;return{value:t,done:!0}}for(o.method=a,o.arg=i;;){var c=o.delegate;if(c){var s=_(c,o);if(s){if(s===v)continue;return s}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(r===f)throw r=p,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);r=m;var l=d(e,n,o);if("normal"===l.type){if(r=o.done?p:h,l.arg===v)continue;return{value:l.arg,done:o.done}}"throw"===l.type&&(r=p,o.method="throw",o.arg=l.arg)}}}function _(e,n){var o=n.method,r=e.iterator[o];if(r===t)return n.delegate=null,"throw"===o&&e.iterator["return"]&&(n.method="return",n.arg=t,_(e,n),"throw"===n.method)||"return"!==o&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+o+"' method")),v;var a=d(r,e.iterator,n.arg);if("throw"===a.type)return n.method="throw",n.arg=a.arg,n.delegate=null,v;var i=a.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,v):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function q(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function I(e){if(e||""===e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function n(){for(;++r<e.length;)if(o.call(e,r))return n.value=e[r],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}throw new TypeError(_typeof(e)+" is not iterable")}return y.prototype=w,r(E,"constructor",{value:w,configurable:!0}),r(w,"constructor",{value:y,configurable:!0}),y.displayName=l(w,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},$(C.prototype),l(C.prototype,c,(function(){return this})),e.AsyncIterator=C,e.async=function(t,n,o,r,a){void 0===a&&(a=Promise);var i=new C(u(t,n,o,r),a);return e.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},$(E),l(E,s,"Generator"),l(E,i,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var o in e)n.push(o);return n.reverse(),function r(){for(;n.length;){var t=n.pop();if(t in e)return r.value=t,r.done=!1,r}return r.done=!0,r}},e.values=I,q.prototype={constructor:q,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(S),!e)for(var n in this)"t"===n.charAt(0)&&o.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function r(o,r){return c.type="throw",c.arg=e,n.next=o,r&&(n.method="next",n.arg=t),!!r}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=o.call(i,"catchLoc"),l=o.call(i,"finallyLoc");if(s&&l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&o.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var a=r;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),S(n),v}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var o=n.completion;if("throw"===o.type){var r=o.arg;S(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,o){return this.delegate={iterator:I(e),resultName:n,nextLoc:o},"next"===this.method&&(this.arg=t),v}},e}function asyncGeneratorStep(t,e,n,o,r,a,i){try{var c=t[a](i),s=c.value}catch(l){return void n(l)}c.done?e(s):Promise.resolve(s).then(o,r)}function _asyncToGenerator(t){return function(){var e=this,n=arguments;return new Promise((function(o,r){var a=t.apply(e,n);function i(t){asyncGeneratorStep(a,o,r,i,c,"next",t)}function c(t){asyncGeneratorStep(a,o,r,i,c,"throw",t)}i(undefined)}))}}window.requestIdleCallback=window.requestIdleCallback||function(t){var e=Date.now();return setTimeout((function(){t({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})}),1)},window.cancelIdleCallback=window.cancelIdleCallback||function(t){clearTimeout(t)},window.copyCode=window.copyCode||function(t,e){var n=document.getElementById(e);if(n){var o=n.innerText;navigator.clipboard.writeText(o);var r=t.innerHTML;t.innerHTML='<i class="fa fa-check-circle"></i> 成功~',setTimeout((function(){t.innerHTML=r}),3e3)}},function(){var t,e=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var t,n;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=((null===(t=window.kr)||void 0===t?void 0:t.siteRoot)||"/")+"config/main.json",e.next=3,fetch(n);case 3:return e.next=5,e.sent.json();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)})));return function(){return t.apply(this,arguments)}}(),n="",o=function(t){var e,n=!(arguments.length>1&&arguments[1]!==undefined)||arguments[1],o=t/1e3,r=Math.floor(o/60/60/24),a=Math.floor(o/60/60-24*r),i=Math.floor(o/60-1440*r-60*a),c=Math.floor(o-86400*r-3600*a-60*i),s=r.toString(),l=a.toString(),u=i.toString(),d=c.toString();return n?(s&&1===s.length&&(s="0"+s),l&&1===l.length&&(l="0"+l),u&&1===u.length&&(u="0"+u),d&&1===d.length&&(d="0"+d),e=s+"天"+l+"小时"+u+"分"+d+"秒"):e=r<540?r<60?s+"天":Math.floor(r/30).toString()+"个月":Math.floor(r/365).toString()+"年",e},r=function(t,e){var n=0;return function(){var o=this,r=arguments;clearTimeout(n),n=setTimeout((function(){t.apply(o,r)}),e||0)}},a=function(){var t,e;t=document.getElementById("krw-toc"),e=function(){var e=t.getElementsByClassName("toc-item"),n=[];try{Array.from(e).forEach((function(t){var e=t.querySelector(".toc-link"),o=decodeURI(e.getAttribute("href"));if("#"!=o.substring(0,1))throw new Error("TOC 小标题链接无效,格式无限");var r=document.getElementById(o.substring(1));if(!r)throw new Error("TOC 小标题链接无效,未找到相关引用");r.setAttribute("data-toc-id",n.length),n.push({at:r,el:t})}))}catch(p){return console.log("错误:",p.message),void Array.from(e).forEach((function(t){t.classList.add("show")}))}var o=-1,a=function(t){if(o!==t){if(-1!==o){n[o].el.classList.remove("active"),n[o].el.classList.remove("show");for(var e=n[o].el;!e.classList.contains("toc");)e.classList.contains("toc-item")&&e.classList.remove("show"),e=e.parentNode}if(-1!==t){n[t].el.classList.add("active"),n[t].el.classList.add("show");for(var r=n[t].el;!r.classList.contains("toc");)r.classList.contains("toc-item")&&r.classList.add("show"),r=r.parentNode}o=t}};if("IntersectionObserver"in window){var i=r((function(t,e){e===window.scrollY?window.requestAnimationFrame((function(){a(t)})):i(t,window.scrollY)}),100),c=new IntersectionObserver((function(t){var e=null;t.forEach((function(t){var n=Number.parseInt(t.target.getAttribute("data-toc-id"),10);!t.isIntersecting&&t.boundingClientRect.top<=t.rootBounds.top?e=n:t.isIntersecting&&t.boundingClientRect.bottom<t.rootBounds.top+t.rootBounds.height/2&&1===t.intersectionRatio&&(e=n-1)})),null!==e&&i(e,window.scrollY)}),{rootMargin:"-62px 0px 0px 0px",threshold:1});n.forEach((function(t){c.observe(t.at)})),window.addEventListener("pjax:before",(function(){c.disconnect(),n.length=0}),{once:!0})}else{var s=function(){n.forEach((function(t){t.h=t.at.getBoundingClientRect().top+window.scrollY-61}))};s();var l=function(){var t;t=!Number.isInteger(o)||o<0||o>n.length-1?0:o;var e=window.scrollY;if(e>=n[t].h)if(e>=n[n.length-1].h)t=n.length-1;else for(;e>=n[t+1].h;)t++;else for(;e<n[t].h&&!(--t<0););return t},u=r((function(){window.requestAnimationFrame((function(){a(l())}))}),100),d=r((function(){s(),window.requestAnimationFrame((function(){a(l())}))}),100);window.addEventListener("resize",d),window.addEventListener("scroll",u),window.addEventListener("pjax:before",(function(){window.removeEventListener("resize",d),window.removeEventListener("scroll",u),n.length=0}),{once:!0})}var f=document.getElementsByClassName("toc-progress-bar")[0],h=document.querySelector(".kratos-post-content"),m=function(){if(h){var t=window.scrollY||document.documentElement.scrollTop,e=h.clientHeight,n=document.documentElement.clientHeight,o=h.offsetTop,r=e>n?e-n:document.documentElement.scrollHeight-n,a=Math.max(0,Math.min((t-o)/r,1)),i=Math.round(100*a);f.style.width=(100*a).toString()+"%",f.setAttribute("aria-valuenow",i)}};window.addEventListener("scroll",(function(){window.requestAnimationFrame(m)})),m()},t&&(null!==t.offsetParent?e():"IntersectionObserver"in window&&new IntersectionObserver(e,{threshold:0,once:!0}).observe(t)),n=document.title,document.querySelectorAll("figure.highlight").forEach((function(t,e){t.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0].getElementsByTagName("tr")[0].getElementsByClassName("code")[0].setAttribute("id","code-".concat(e)),t.innerHTML+='<button class="copy" onclick="copyCode(this, \'code-'.concat(e,'\')">\n <i class="fa fa-copy"></i> 复制\n </button>')})),"undefined"!=typeof $.fancybox&&($.fancybox.defaults.hash=!1,$(".kratos-hentry").each((function(t){$(this).find("img").each((function(){if(!($(this).parent().hasClass("fancybox")||$(this).parent().hasClass("qrcode")||$(this).parent().is("a"))){var t=this.alt;t&&$(this).after('<span class="caption">'+t+"</span>"),$(this).wrap('<a rel="gallery" href="'+this.src+'" data-fancybox="gallery" data-caption="'+t+'"></a>')}}))})),$(".fancybox").fancybox()),function(){var t="undefined"!=typeof window,e=t&&!("onscroll"in window)||"undefined"!=typeof navigator&&/(gle|ing|ro|msn)bot|crawl|spider|yand|duckgo/i.test(navigator.userAgent),n=t&&"IntersectionObserver"in window,o=document.querySelector(".post-comments.lazy-load"),r=function(){window.loadCommentsEventHandler&&window.cancelIdleCallback(window.loadCommentsEventHandler),"undefined"!=typeof load_comm&&null!==load_comm&&(window.loadCommentsEventHandler=window.requestIdleCallback(load_comm),load_comm=null)};if(t&&!e&&n&&null!==o){var a=new IntersectionObserver((function(t){t[0].isIntersecting&&(r(),a.disconnect())}),{threshold:0});a.observe(o)}else r()}()},i=function(e){!function(t){for(var e=document.getElementsByClassName("kratos-entry-thumb-new-img"),n=t.cover&&t.cover.randomAmount||20,o=t.cover&&t.cover.baseUrl||"https://cdn.jsdelivr.net/npm/hexo-theme-kratos-rebirth@latest/source/images/thumb/",r=t.cover&&t.cover.filenameTemplate||"thumb_{no}.webp",a=new Array(n+1),i=function(){for(var t,e=5;e>0&&(t=Math.floor(Math.random()*n+1),a[t]);)e--;if(e<=0){t=-1;for(var o=1;o<=n;o++)if(!a[o]){t=o;break}if(-1===t){for(var r=1;r<=n;r++)a[r]=!1;t=Math.floor(Math.random()*n+1)}}return a[t]=!0,t},c=0,s=e.length;c<s;c++)if(!$(e[c]).attr("src")){var l=i(),u=r.replace("{no}",l.toString()),d=void 0;d=u.includes("//")?u:"/"===o.substring(o.length-1)?o+u:o+"/"+u,$(e[c]).attr("src",d)}}(e),function(e){t="\n\n-------------------------\n".concat(e.copyrightNotice,"\n作者:").concat(document.querySelector("meta[name='author']").getAttribute("content"),"\n来源:").concat(document.title,"\n链接:").concat(window.location.href,"\n")}(e),function(t){if(t.expire_day){var e=document.getElementById("expire-alert");if(e){var n=e.querySelector("time"),r=new Date(parseInt(n.getAttribute("datetime"))),a=Date.now()-r;a>24*t.expire_day*3600*1e3&&(n.innerText=o(a,!1),e.classList.remove("hidden"))}}}(e)};function c(){var r,s,l;document.removeEventListener("DOMContentLoaded",c,!1),window.removeEventListener("load",c,!1),e().then((function(e){!function(e){e.copyrightNotice&&(document.body.oncopy=function(e){if(t){var n=window.getSelection().toString();n.length>150&&(e.preventDefault(),e.clipboardData&&e.clipboardData.setData("text/plain",n+t))}})}(e),function(t){if(t.siteLeaveEvent){var e,o=$('[rel="icon"]').attr("href");document.addEventListener("visibilitychange",(function(){document.hidden?(document.title=t.leaveTitle,t.leaveLogo&&$('[rel="icon"]').attr("href",t.leaveLogo),clearTimeout(e)):(document.title=t.returnTitle+" "+n,t.leaveLogo&&$('[rel="icon"]').attr("href",o),e=setTimeout((function(){document.title=n,e=0}),2e3))}))}}(e),function(t){var e=new Date(t.createTime),n=document.getElementById("span_dt");setInterval((function(){n.innerText=o(Date.now()-e)}),1e3)}(e),function(t){$(document).on("click",".donate",(function(){layer.open({type:1,area:["300px","370px"],title:t.donateBtn,resize:!1,scrollbar:!1,content:'<div class="donate-box"><div class="meta-pay text-center"><strong>'+t.scanNotice+'</strong></div><div class="qr-pay text-center"><img class="pay-img" id="alipay_qr" src="'+t.qr_alipay+'"><img class="pay-img d-none" id="wechat_qr" src="'+t.qr_wechat+'"></div><div class="choose-pay text-center mt-2"><input id="alipay" type="radio" name="pay-method" checked><label for="alipay" class="pay-button"><img src="/images/alipay.webp"></label><input id="wechatpay" type="radio" name="pay-method"><label for="wechatpay" class="pay-button"><img src="/images/wechat.webp"></label></div></div>'}),$(".choose-pay input[type='radio']").click((function(){var t=$(this).attr("id");"alipay"==t&&($(".qr-pay #alipay_qr").removeClass("d-none"),$(".qr-pay #wechat_qr").addClass("d-none")),"wechatpay"==t&&($(".qr-pay #alipay_qr").addClass("d-none"),$(".qr-pay #wechat_qr").removeClass("d-none"))}))}))}(e),function(t){if(t.topNavScrollToggle){var e=window.innerHeight,n=!1;window.addEventListener("wheel",(function(){window.requestAnimationFrame((function(){e<window.scrollY?n||(document.body.classList.add("nav-up"),n=!0):e>window.scrollY&&n&&(document.body.classList.remove("nav-up"),n=!1),e=window.scrollY}))}))}}(e),i(e),window.addEventListener("pjax:complete",(function(){i(e)}))})),r=!1,s=function(){window.requestAnimationFrame((function(){window.scrollY>200?r||(document.body.classList.add("scroll-down"),r=!0):r&&(document.body.classList.remove("scroll-down"),r=!1)}))},$(".gotop-box").on("click",(function(t){return $("html, body").animate({scrollTop:$("html").offset().top},500),!1})),s(),window.addEventListener("scroll",s),(l=$("#kratos-menu-wrap").clone()).attr({id:"offcanvas-menu"}),l.find("> ul").attr({id:""}).addClass("ul-me"),$("#kratos-page").prepend(l),$(".js-kratos-nav-toggle").on("click",(function(){$(".nav-toggle").hasClass("toon")?($(".nav-toggle").removeClass("toon"),$("#offcanvas-menu").css("right","-240px")):($(".nav-toggle").addClass("toon"),$("#offcanvas-menu").css("right","0px"))})),$("#offcanvas-menu").css("height",$(window).height()),$("#offcanvas-menu").css("right","-240px"),$(window).resize((function(){var t=$(window);$("#offcanvas-menu").css("height",t.height()),t.width()>769&&$(".nav-toggle").hasClass("toon")&&($(".nav-toggle").removeClass("toon"),$("#offcanvas-menu").css("right","-240px"))})),$(document).click((function(t){var e=$("#offcanvas-menu,.js-kratos-nav-toggle");e.is(t.target)||0!==e.has(t.target).length||$(".nav-toggle").hasClass("toon")&&($(".nav-toggle").removeClass("toon"),$("#offcanvas-menu").css("right","-240px"))})),$(document).on("click",".xHeading",(function(t){$(this).next().slideToggle(300),$(this).parent(".xControl").hasClass("active")?$(this).parent(".xControl").removeClass("active"):$(this).parent(".xControl").addClass("active"),t.preventDefault()})),$(document).on("click",".share",(function(){$(".share-wrap").fadeToggle("slow")})),$(document).on("click","a[class=toc-link]",(function(){return $("html, body").animate({scrollTop:$(decodeURI($(this).attr("href"))).offset().top-60},500),!1})),a()}window.addEventListener("pjax:complete",(function(){a(),"undefined"!=typeof MathJax&&MathJax.Hub.Typeset()})),"complete"===document.readyState?setTimeout(c):(document.addEventListener("DOMContentLoaded",c,!1),window.addEventListener("load",c,!1))}();
//# sourceMappingURL=../maps/kratosr.min.js.map