From 823d397f12eeff0c7cd6e33cf141bee6c9f85bc8 Mon Sep 17 00:00:00 2001 From: hehh Date: Tue, 25 Nov 2025 10:37:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(about):=20=E4=BC=98=E5=8C=96=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E7=BB=84=E4=BB=B6=E4=B8=BB=E9=A2=98=E4=B8=8E=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E7=9B=91=E5=90=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 合并主题与语言变化的监听器,统一使用MutationObserver - 增加对data-lang属性变化的监听 - 移除单独的语言按钮点击事件监听 - 统一延迟重新加载评论组件的时机至300ms - 提高代码可维护性和响应一致性 --- js/about.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/js/about.js b/js/about.js index 830d35d..4ce492b 100644 --- a/js/about.js +++ b/js/about.js @@ -581,32 +581,21 @@ class UIManager { this.enhanceMobileArtalk(container, lang); } - // 监听主题变化 + // 监听主题/语言变化 const themeObserver = new MutationObserver(() => { const newTheme = document.documentElement.getAttribute('data-theme'); - if (newTheme !== currentTheme) { - // 重新加载整个评论组件而不是仅仅设置主题 + const newLang = document.documentElement.getAttribute('data-lang'); + // 延迟执行 + setTimeout(() => { + // 重新加载整个评论组件 this.reloadArtalk(); - } + }, 300); }); themeObserver.observe(document.documentElement, { attributes: true, - attributeFilter: ['data-theme'] + attributeFilter: ['data-theme', 'data-lang'] }); - - // 监听语言变化 - const langBtn = document.getElementById('lang-btn'); - if (langBtn) { - langBtn.addEventListener('click', () => { - // 延迟执行以确保语言已经切换 - setTimeout(() => { - // 重新加载整个评论组件而不是仅仅更新语言 - this.reloadArtalk(); - }, 100); - }); - } - // 初始化自定义样式 this.updateCustomStyles(container, currentTheme); }