mirror of
https://github.com/MCKero6423/fuwari.git
synced 2026-10-02 03:15:35 +00:00
feat:按照评论组件的方法修复抽搐问题
This commit is contained in:
1 parent
e0557c88c4
commit
2df975c22c
1 file changed
+25
-41
@@ -141,50 +141,34 @@ const jsonLd = {
|
|||||||
<link rel="stylesheet" href="https://ai.zhheo.com/static/public/tianli_gpt.min.css">
|
<link rel="stylesheet" href="https://ai.zhheo.com/static/public/tianli_gpt.min.css">
|
||||||
|
|
||||||
<script is:inline>
|
<script is:inline>
|
||||||
// 1. 设置全局参数
|
// 定义加载函数(模仿你的 loadTwikoo)
|
||||||
window.tianliGPT_postSelector = '.markdown-content';
|
function loadHongmoAI() {
|
||||||
window.tianliGPT_wordLimit = 700;
|
// 1. 基础配置
|
||||||
window.tianliGPT_Title = '智能摘要';
|
window.tianliGPT_postSelector = '.markdown-content';
|
||||||
window.tianliGPT_key = 'S-HMJ7UXQGBIAZ0U8Q';
|
window.tianliGPT_wordLimit = 700;
|
||||||
|
window.tianliGPT_key = 'S-HMJ7UXQGBIAZ0U8Q';
|
||||||
|
|
||||||
(function() {
|
// 2. 防抖检查(解决“抽搐”的核心):如果已经生成了摘要,绝对不要运行第二次!
|
||||||
// 定义一个“哨兵”计数器,防止死循环
|
var existing = document.querySelector('.tianli-gpt-response');
|
||||||
var checkCount = 0;
|
if (existing) return;
|
||||||
var maxChecks = 100; // 最多等 5秒 (100 * 50ms)
|
|
||||||
|
|
||||||
function initHongmo() {
|
// 3. 动态加载脚本
|
||||||
var content = document.querySelector('.markdown-content');
|
var script = document.createElement('script');
|
||||||
|
script.src = 'https://ai.zhheo.com/static/public/tianli_gpt.min.js';
|
||||||
// 1. 还没找到文章内容?那就过 50ms 再来看看
|
script.defer = true;
|
||||||
if (!content) {
|
document.body.appendChild(script);
|
||||||
if (checkCount < maxChecks) {
|
}
|
||||||
checkCount++;
|
|
||||||
setTimeout(initHongmo, 50);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. [关键修复] 防抽搐:检查是否已经有生成的摘要了?
|
// 4. 核心逻辑:双重保险
|
||||||
// 如果已经有 .tianli-gpt-response 元素,说明插件已经在运行,直接退出,别搞第二次
|
// 情况A: 这是一个 Swup 跳转页面 -> 监听 swup:page:view 事件,且只执行一次
|
||||||
if (content.querySelector('.tianli-gpt-response')) {
|
document.addEventListener('swup:page:view', loadHongmoAI, { once: true });
|
||||||
return;
|
|
||||||
}
|
// 情况B: 这是一个直接刷新的页面 -> 立即执行(因为可能没有 swup 事件)
|
||||||
|
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||||
// 3. 清理旧脚本,防止重复
|
loadHongmoAI();
|
||||||
var oldScript = document.getElementById('tianli-gpt-script');
|
} else {
|
||||||
if (oldScript) { oldScript.remove(); }
|
document.addEventListener('DOMContentLoaded', loadHongmoAI);
|
||||||
|
}
|
||||||
// 4. 一切就绪,注入新脚本
|
|
||||||
var script = document.createElement('script');
|
|
||||||
script.id = 'tianli-gpt-script';
|
|
||||||
script.src = 'https://ai.zhheo.com/static/public/tianli_gpt.min.js';
|
|
||||||
script.async = true;
|
|
||||||
document.body.appendChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 立即开始执行检测
|
|
||||||
initHongmo();
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user