优化加载卡顿问题,最稳定版本

This commit is contained in:
Vaica committed 2026-06-02 16:26:38 +08:00
1 parent fadefdc0a1
commit 8c1ee075e8
3 files changed
+71 -111

No files matched your search

+44 -79
View File
@@ -94,89 +94,54 @@ document.addEventListener("pjax:success", function () {
});
// pjax加载完成
// 代码折叠初始化 — 独立监听器,确保不被其他初始化错误影响
document.addEventListener("pjax:complete", function () {
setTimeout(function() {
if (typeof window.initCodeFold === 'function') window.initCodeFold();
}, 200);
});
document.addEventListener("pjax:complete", function () {
// pjax完成动画
if (typeof NProgress !== 'undefined') {
NProgress.done();
}
// 重载一些js样式调整
// 立即执行:进度条、基础 UI
if (typeof NProgress !== 'undefined') NProgress.done();
pjax_reload();
// 初始化代码复制
if (typeof initCodeCopy === 'function') initCodeCopy();
// 初始化段落评论
if (typeof window.initParagraphComments === 'function') {
try {
window.initParagraphComments();
} catch (e) {
console.error('initParagraphComments error:', e);
// 下一帧执行:轻量初始化
requestAnimationFrame(function() {
if (typeof initCodeCopy === 'function') initCodeCopy();
if (typeof window.initSearch === 'function') {
try { window.initSearch(); } catch(e) {}
}
}
if (typeof window.refreshFloatingTools === 'function') {
window.refreshFloatingTools();
} else if (typeof window.initFloatingTools === 'function') {
try { window.initFloatingTools(); } catch(e) {}
}
// 文章动画
if (typeof window.initPostScrollspy === 'function') window.initPostScrollspy();
});
// 初始化无限加载
if (typeof window.initInfiniteScroll === 'function' && window.enableInfiniteScroll) {
window.initInfiniteScroll();
}
// 初始化友链状态
if (typeof window.initLinkStatus === 'function') {
try {
window.initLinkStatus();
} catch(e) { console.error('initLinkStatus error:', e); }
}
// 重载评论
if (typeof window.initArtalk === 'function') {
try {
window.initArtalk();
} catch(e) { console.error('initArtalk error:', e); }
}
// 重载不蒜子统计
if (typeof window.bsz_fetch === 'function') {
try {
window.bsz_fetch();
} catch(e) { console.error('bsz_fetch error:', e); }
}
// 重载 Search 和 Floating Tools (Moved from main.js)
if (typeof window.refreshFloatingTools === 'function') {
window.refreshFloatingTools();
} else if (typeof window.initFloatingTools === 'function') {
requestAnimationFrame(function() {
try {
window.initFloatingTools();
} catch(e) { console.error('initFloatingTools error:', e); }
});
}
if (typeof window.initSearch === 'function') {
try {
window.initSearch();
} catch(e) { console.error('initSearch error:', e); }
}
// 空闲时执行:非关键功能
var idle = window.requestIdleCallback || function(fn) { return setTimeout(fn, 200); };
idle(function() {
if (typeof window.initParagraphComments === 'function') {
try { window.initParagraphComments(); } catch(e) {}
}
if (typeof window.initInfiniteScroll === 'function' && window.enableInfiniteScroll) {
window.initInfiniteScroll();
}
if (typeof window.initLinkStatus === 'function') {
try { window.initLinkStatus(); } catch(e) {}
}
if (typeof window.initArtalk === 'function') {
try { window.initArtalk(); } catch(e) {}
}
if (typeof window.bsz_fetch === 'function') {
try { window.bsz_fetch(); } catch(e) {}
}
if (typeof window.initImageFrameReveal === 'function') {
try { window.initImageFrameReveal(); } catch(e) {}
}
// 链接卡片和中英文间距(DOM 扫描,非关键)
if (typeof window.initLinkify === 'function') window.initLinkify();
if (typeof window.initPangu === 'function') window.initPangu();
});
// 重载图片框架滚动显示
if (typeof window.initImageFrameReveal === 'function') {
try {
window.initImageFrameReveal();
} catch(e) { console.error('initImageFrameReveal error:', e); }
}
// 重载文章动画
if (typeof window.initPostScrollspy === 'function') window.initPostScrollspy();
// 重载链接卡片
if (typeof window.initLinkify === 'function') window.initLinkify();
// 重载中英文间距
if (typeof window.initPangu === 'function') window.initPangu();
refreshHeatmap();
// 延迟:代码折叠
setTimeout(function() {
if (typeof window.initCodeFold === 'function') window.initCodeFold();
}, 300);
});