mirror of
https://github.com/MCKero6423/fuwari.git
synced 2026-10-02 03:15:35 +00:00
feat:修复AI摘要插件打字抽搐问题
This commit is contained in:
1 parent
bf8b8c8c19
commit
e0557c88c4
1 file changed
+42
-15
@@ -141,23 +141,50 @@ const jsonLd = {
|
||||
<link rel="stylesheet" href="https://ai.zhheo.com/static/public/tianli_gpt.min.css">
|
||||
|
||||
<script is:inline>
|
||||
var tianliGPT_postSelector = '.markdown-content';
|
||||
var tianliGPT_wordLimit = 700;
|
||||
var tianliGPT_Title = '智能摘要';
|
||||
var tianliGPT_key = 'S-HMJ7UXQGBIAZ0U8Q';
|
||||
// 1. 设置全局参数
|
||||
window.tianliGPT_postSelector = '.markdown-content';
|
||||
window.tianliGPT_wordLimit = 700;
|
||||
window.tianliGPT_Title = '智能摘要';
|
||||
window.tianliGPT_key = 'S-HMJ7UXQGBIAZ0U8Q';
|
||||
|
||||
// 延迟 300ms 执行,确保 Swup 切换后新内容已就绪
|
||||
setTimeout(function() {
|
||||
var oldScript = document.getElementById('tianli-gpt-script');
|
||||
if (oldScript) { oldScript.remove(); }
|
||||
(function() {
|
||||
// 定义一个“哨兵”计数器,防止死循环
|
||||
var checkCount = 0;
|
||||
var maxChecks = 100; // 最多等 5秒 (100 * 50ms)
|
||||
|
||||
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);
|
||||
}, 300);
|
||||
function initHongmo() {
|
||||
var content = document.querySelector('.markdown-content');
|
||||
|
||||
// 1. 还没找到文章内容?那就过 50ms 再来看看
|
||||
if (!content) {
|
||||
if (checkCount < maxChecks) {
|
||||
checkCount++;
|
||||
setTimeout(initHongmo, 50);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. [关键修复] 防抽搐:检查是否已经有生成的摘要了?
|
||||
// 如果已经有 .tianli-gpt-response 元素,说明插件已经在运行,直接退出,别搞第二次
|
||||
if (content.querySelector('.tianli-gpt-response')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 清理旧脚本,防止重复
|
||||
var oldScript = document.getElementById('tianli-gpt-script');
|
||||
if (oldScript) { oldScript.remove(); }
|
||||
|
||||
// 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>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user