From 6c4b4b78090cfb68bcf4f0b91bcb249de27fb061 Mon Sep 17 00:00:00 2001 From: Vaica <94612053+zqlit@users.noreply.github.com> Date: Sat, 31 Jan 2026 23:01:35 +0800 Subject: [PATCH] fixed bug --- themes/Ying/assets/js/barrage.js | 28 ++++++++++++----- .../assets/js/modules/paragraph-comments.js | 31 ++++++++++++++++--- themes/Ying/layouts/partials/artalk.html | 2 +- themes/Ying/layouts/partials/head.html | 2 +- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/themes/Ying/assets/js/barrage.js b/themes/Ying/assets/js/barrage.js index ad7518bc..1eb91233 100644 --- a/themes/Ying/assets/js/barrage.js +++ b/themes/Ying/assets/js/barrage.js @@ -37,6 +37,19 @@ // 检查 Artalk 实例并尝试获取数据 const checkArtalk = () => { if (isResolved) return; + + // 如果当前页面没有评论区,不要等待 Artalk 初始化,直接返回空 + // 这样可以避免在无评论页(如首页)长时间等待超时 + const hasCommentSection = document.getElementById('artalk') || + document.getElementById('Comments') || + document.querySelector('.atk-comment-wrap'); + if (!hasCommentSection) { + // 延迟一点点返回,确保逻辑统一 + setTimeout(() => { + tryResolve([], 'no-comment-section'); + }, 100); + return; + } if (window.artalk) { // 1. 尝试绑定事件 (只绑定一次) @@ -358,13 +371,14 @@ document.getElementById('Comments') || document.querySelector('.atk-comment-wrap'); - if (!hasCommentSection) { - // console.log('[Barrage] 当前页面无评论区,隐藏弹幕'); - if (barrageInstance) { - barrageInstance.hide(); - } - return; - } + // 即使没有评论区,也不要隐藏弹幕,允许 Hitokoto 或上一页的数据继续播放 + // if (!hasCommentSection) { + // // console.log('[Barrage] 当前页面无评论区,隐藏弹幕'); + // if (barrageInstance) { + // barrageInstance.hide(); + // } + // return; + // } // 1. 获取容器,如果没有则动态创建 let container = document.querySelector('.barrager'); diff --git a/themes/Ying/assets/js/modules/paragraph-comments.js b/themes/Ying/assets/js/modules/paragraph-comments.js index 72cff61a..44957580 100644 --- a/themes/Ying/assets/js/modules/paragraph-comments.js +++ b/themes/Ying/assets/js/modules/paragraph-comments.js @@ -232,17 +232,38 @@ } } + // Safe Get Comment List Helper + function getCommentListSafe(artalkInstance) { + var inst = artalkInstance || window.artalk; + if (!inst) return []; + + if (typeof inst.getCommentList === 'function') return inst.getCommentList(); + if (typeof inst.getComments === 'function') return inst.getComments(); + + // Try context access (Artalk v2) + if (inst.ctx && typeof inst.ctx.get === 'function') { + var list = inst.ctx.get('list'); + if (list && typeof list.getComments === 'function') { + return list.getComments(); + } + } + + return []; + } + function setupArtalkHook(artalk) { // Initial load - var list = artalk.getCommentList(); + var list = getCommentListSafe(artalk); if (list && list.length > 0) { processComments(); } // Listen for updates - artalk.on('list-loaded', function() { - setTimeout(processComments, 500); - }); + if (typeof artalk.on === 'function') { + artalk.on('list-loaded', function() { + setTimeout(processComments, 500); + }); + } } // Performance Optimized: Build Index Once @@ -284,7 +305,7 @@ }); document.querySelectorAll('.paragraph-comment-count').forEach(el => el.remove()); - var comments = window.artalk.getCommentList(); + var comments = getCommentListSafe(window.artalk); var quoteMap = {}; // Group comments by quote diff --git a/themes/Ying/layouts/partials/artalk.html b/themes/Ying/layouts/partials/artalk.html index fcfcd38b..e7518a64 100644 --- a/themes/Ying/layouts/partials/artalk.html +++ b/themes/Ying/layouts/partials/artalk.html @@ -73,7 +73,7 @@ site: '{{ .Site.Params.artalk.site }}', aiBadge: '{{ .Site.Params.artalk.ai_badge | default "AI" }}', pageKey: '{{ .RelPermalink }}', - emoticons: '{{ .Site.Params.artalk.emoticons | relURL }}', + emoticons: '{{ .Site.Params.artalk.emoticons | absURL }}', aiComment: {{ if .Params.ai_comment }} {{ $avatar := .Site.Params.ai.avatar }} {{ if not $avatar }}{{ $avatar = .Site.Params.author.avatar }}{{ end }} diff --git a/themes/Ying/layouts/partials/head.html b/themes/Ying/layouts/partials/head.html index 4d4bb912..4df8976f 100644 --- a/themes/Ying/layouts/partials/head.html +++ b/themes/Ying/layouts/partials/head.html @@ -77,7 +77,7 @@ artalk: { server: "{{ .Site.Params.artalk.server }}", site: "{{ .Site.Params.artalk.site }}", - emoticons: "{{ .Site.Params.artalk.emoticons | relURL }}", + emoticons: "{{ .Site.Params.artalk.emoticons | absURL }}", gravatar: "{{ .Site.Params.artalk.gravatar }}" }, author: {