From 88b22d8a2cabde532ce9a66eca7075388a575f98 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 12:55:30 +0000 Subject: [PATCH 2/2] Fix cookie-consent-gated script loading: TermsFeed callbacks, JSON consent check, TianliGPT global scope Co-authored-by: MCKero6423 <222912022+MCKero6423@users.noreply.github.com> --- src/components/comment/Twikoo.astro | 28 +++++++++++++++--- src/layouts/Layout.astro | 40 +++++++++++++++++++++---- src/pages/posts/[...slug].astro | 45 +++++++++++++++++++++-------- 3 files changed, 91 insertions(+), 22 deletions(-) diff --git a/src/components/comment/Twikoo.astro b/src/components/comment/Twikoo.astro index 83ec339..7b200ab 100644 --- a/src/components/comment/Twikoo.astro +++ b/src/components/comment/Twikoo.astro @@ -14,11 +14,31 @@ const config = {
diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index cdec702..318892c 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -148,8 +148,10 @@ const jsonLd = { window.tianliGPT_Title = '智能摘要'; window.tianliGPT_key = 'S-HMJ7UXQGBIAZ0U8Q'; - // 立即尝试初始化 - function tryInitTianliGPT() { + // Expose on window so the loader script's onload handler (in a different + // inline script block) can always reach the latest version of this function + // after Swup page transitions replace the DOM content. + window._tryInitTianliGPT = function tryInitTianliGPT() { if (typeof window.tianliGPT === 'object' && typeof window.tianliGPT.checkURLAndRun === 'function') { @@ -166,33 +168,52 @@ const jsonLd = { }, 500); } else if (window.tianliGPT_scriptLoaded) { // 脚本已请求加载但尚未就绪,继续等待 - setTimeout(tryInitTianliGPT, 200); + setTimeout(window._tryInitTianliGPT, 200); } // else: 脚本未加载(无功能性同意),停止轮询 - } + }; // 开始尝试 - tryInitTianliGPT(); + window._tryInitTianliGPT();