mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-17 19:11:52 +00:00
1 line
5.0 KiB
JavaScript
1 line
5.0 KiB
JavaScript
(()=>{const s=new Set($('link[href*=".css"]').map((n,o)=>$(o).attr("href")).get()),l=new Set($('script[src*=".js"]').map((n,o)=>$(o).attr("src")).get()),o=()=>{var n=(new Date).getTime();return window.pjaxSerialNumber=n,console.log("sn = "+n),n},e=n=>"/"!==n.pathname&&0!==$(".banner").length?(window.initTop=99999999,window.innerHeight/4):0,c=(o,e,t)=>{if(e>=o.length)t&&t();else{let n=$(o[e]).attr("src");l.has(n)?c(o,e+1,t):(console.log((t?"同步":"异步")+"顺序加载js "+n),Utils.cachedScript(n).done(function(){console.log((t?"同步":"异步")+"顺序加载js完成 "+n),l.add(n),window.DProgress&&DProgress.inc(),c(o,e+1,t)}).fail(function(){console.log((t?"同步":"异步")+"顺序加载js失败 "+n),c(o,e+1,t)}))}};$(document).on("click","a[target!=_blank][href]:not([data-not-pjax])",n=>{$.pjax.click(n,".column-main",{scrollTo:e(n.currentTarget),fragment:".column-main",serialNumber:o(),timeout:8e3})}),$(document).on("submit","form[data-pjax]",function(n){$.pjax.submit(n,".column-main",{scrollTo:e(n.currentTarget),fragment:".column-main",serialNumber:o(),timeout:8e3})}),$(document).on("pjax:click",function(n,o){console.log("------------------------"),console.log("pjax:click sn = "+o.serialNumber)}),$(document).on("pjax:beforeSend",function(n,o,e){console.log("pjax:beforeSend sn = "+e.serialNumber),$("html").addClass("pjax-loading")}),$(document).on("pjax:start",function(n,o,e){console.log("pjax:start sn = "+e.serialNumber),window.DProgress&&DProgress.start(),$(".pjax-close").remove()}),$(document).on("pjax:send",function(n,o,e){console.log("pjax:send sn = "+e.serialNumber)}),$(document).on("pjax:clicked",function(n,o){console.log("pjax:clicked sn = "+o.serialNumber)}),$(document).on("pjax:beforeReplace",function(n,o,e){console.log("pjax:beforeReplace sn = "+e.serialNumber),$(".navbar-nav .current,.panel-side-menu .current").removeClass("current"),commonContext.initNavbar(),0<$("html.disable-scroll").length&&$(".navbar-mask").trigger("click")}),$(document).on("pjax:success",async function(n,o,e,t,i){i=i.serialNumber;if(console.log("pjax:success sn = "+i),window.pjaxSerialNumber===i){commonContext.initGallery(),commonContext.initTocAndNotice(),$("html").removeClass("pjax-loading");const a=$($.parseHTML(o,document,!0)),r=$("head");r.find("meta").remove(),r.find('link[rel="canonical"]').remove(),r.append(a.filter("meta")),r.append(a.filter('link[rel="canonical"]')),a.filter("link").filter(function(){var n=$(this).is("[data-pjax]"),o=$(this).attr("href"),o=o&&(o.startsWith("/plugins/PluginHighlightJS/")||o.startsWith("/plugins/plugin-katex/"));return n||o}).each(function(){let n=$(this).attr("href");s.has(n)||(r.append($(this)),console.log("加载css "+$(this).attr("href")),this.onload=function(){s.add(n),window.DProgress&&DProgress.inc(),console.log("加载css完成 "+$(this).attr("href"))})});let n=a.filter("script").filter(function(){var n=$(this).is("[data-pjax]"),o=$(this).attr("src"),o=o&&(o.startsWith("/plugins/PluginHighlightJS/")||o.startsWith("/plugins/text-diagram/"));return n||o});if(0<n.length){n.filter("[async]").each(function(){let n=$(this).attr("src");l.has(n)||(console.log("异步无序加载js "+n),Utils.cachedScript(n).done(function(){console.log("异步无序js完成 "+n),window.DProgress&&DProgress.inc(),l.add(n)}).fail(function(){console.log("异步无序js失败 "+n)}))}),new Promise(()=>{c(n.filter("[defer]"),0)});let o=n.filter(":not([async]):not([defer])");0<o.length&&await new Promise(n=>{c(o,0,n)})}console.log("全部处理完成"),window.pjaxSerialNumber===i&&(window.journalPjax&&window.journalPjax(i),window.postPjax&&window.postPjax(i),window.initKatex&&window.initKatex(),window.initMermaid&&window.initMermaid(),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.initCarousel(),commonContext.closeFancybox(),window.DProgress)&&DProgress.done()}}),$(document).on("pjax:timeout",function(n,o,e){console.log("pjax:timeout sn = "+e.serialNumber)}),$(document).on("pjax:error",function(n,o,e,t,i){console.log(`pjax:error sn = ${i.serialNumber} error `+t)}),$(document).on("pjax:complete",function(n,o,e,t){if(console.log("pjax:complete sn = "+t.serialNumber),DreamConfig.site_comment){const n=document.title,o=window.location.pathname,e=window.location.href;window.history&&window.history.replaceState&&window.history.replaceState({url:e,title:n,path:o},n,e)}}),$(document).on("pjax:end",function(n,o,e){console.log("pjax:end sn = "+e.serialNumber),null==o&&(commonContext.initTocAndNotice(),commonContext.initCarousel(),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.closeFancybox(),window.DProgress&&DProgress.done(),$("html").removeClass("pjax-loading"))}),$(document).on("pjax:popstate",function(n){console.log("pjax:popstate")}),window.addEventListener("popstate",function(n){if(console.log("popstate event triggered"),DreamConfig.site_comment&&n.state){const n=window.location.href;$.pjax.reload(".column-main",{container:".column-main",push:!1,url:n,fragment:".column-main",serialNumber:o(),timeout:8e3})}})})(); |