From 26e8e68b4e1a35476c46e5ba9f49e48f1b76c71c Mon Sep 17 00:00:00 2001 From: hehh Date: Tue, 25 Nov 2025 14:16:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(about):=20=E4=BC=98=E5=8C=96=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E5=A4=9A=E8=AF=AD=E8=A8=80=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=92=8CUI=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取语言判断逻辑到常量 isZh,提升代码可读性 - 统一使用 isZh 判断替换原有的 lang === 'zh' 条件表达式 - 移除CSS中冗余的发送按钮文字定义,改由JS统一控制 - 完善时间显示 --- css/artalk.css | 8 -------- js/about.js | 33 +++++++++++++++++---------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/css/artalk.css b/css/artalk.css index 77a8989..5dd8d41 100644 --- a/css/artalk.css +++ b/css/artalk.css @@ -124,14 +124,6 @@ transform: translateY(0) !important; } -.atk-send-btn:before { - content: "发送" !important; -} - -[data-lang="en"] .atk-send-btn:before { - content: "Send" !important; -} - .atk-list-header { padding: 20px !important; border-bottom: 1px solid rgba(128, 128, 128, 0.15) !important; diff --git a/js/about.js b/js/about.js index 754a723..79c30a2 100644 --- a/js/about.js +++ b/js/about.js @@ -529,8 +529,9 @@ class UIManager { const isHttps = location.protocol === 'https:'; const isLocal = !!(window.SiteConfig?.dev?.isLocal); const lang = getStoredLanguage(); + const isZh = lang === 'zh'; if (!isHttps || isLocal) { - const msg = lang === 'zh' ? '当前评论区已关闭' : 'Comments are closed'; + const msg = isZh ? '当前评论区已关闭' : 'Comments are closed'; $('#artalk-container').html(`
${msg}
`); return; } @@ -543,7 +544,13 @@ class UIManager { server: window.SiteConfig.artalk.server, site: window.SiteConfig.artalk.site, // 多语言支持 - locale: lang === 'zh' ? 'zh-CN' : 'en-US', + locale: isZh ? 'zh-CN' : 'en-US', + // 自定义占位符(支持多语言) + placeholder: isZh ? '说点什么吧...支持 Markdown 语法,可 @用户、发送表情' : 'Leave a comment... Supports Markdown, @mentions, and Send 😊', + + // 发送按钮文字(多语言) + sendBtn: isZh ? '发送' : 'Send', + loginBtn: isZh ? '发送' : 'Send', // 主题支持 darkMode: document.documentElement.getAttribute('data-theme') === 'night', @@ -553,12 +560,6 @@ class UIManager { // 启用 Markdown markdown: true, - // 自定义占位符(支持多语言) - placeholder: lang === 'zh' ? '说点什么吧...支持 Markdown 语法,可 @用户、发送表情' : 'Leave a comment... Supports Markdown, @mentions, and Send 😊', - - // 发送按钮文字(多语言) - sendBtn: lang === 'zh' ? '发送' : 'Send', - // 表情面板 emoji: { // 使用默认表情包 @@ -591,21 +592,21 @@ class UIManager { const now = new Date(); const diffSec = Math.floor((now - date) / 1000); - if (diffSec < 60) return lang === 'zh' ? '刚刚' : 'Just now'; - if (diffSec < 3600) return lang === 'zh' ? `${Math.floor(diffSec / 60)}分钟前` : `${Math.floor(diffSec / 60)} minutes ago`; - if (diffSec < 86400) return lang === 'zh' ? `${Math.floor(diffSec / 3600)}小时前` : `${Math.floor(diffSec / 3600)} hours ago`; + if (diffSec < 60) return isZh ? '刚刚' : 'Just now'; + if (diffSec < 3600) return isZh ? `${Math.floor(diffSec / 60)}分钟前` : `${Math.floor(diffSec / 60)} minutes ago`; + if (diffSec < 86400) return isZh ? `${Math.floor(diffSec / 3600)}小时前` : `${Math.floor(diffSec / 3600)} hours ago`; const isToday = date.toDateString() === now.toDateString(); - if (isToday) return lang === 'zh' ? + if (isToday) return isZh ? `今天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}` : `Today ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`; const isYesterday = new Date(now - 86400000).toDateString() === date.toDateString(); - if (isYesterday) return lang === 'zh' ? + if (isYesterday) return isZh ? `昨天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}` : `Yesterday ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`; - return date.toLocaleString(lang === 'zh' ? 'zh-CN' : 'en-US', { + return date.toLocaleString(isZh ? 'zh-CN' : 'en-US', { year: 'numeric', month: '2-digit', day: '2-digit', @@ -630,11 +631,11 @@ class UIManager { this.enhanceArtalkUI(); } catch (e) { console.error("Artalk Error", e); - const msg = lang === 'zh' ? '当前评论区已关闭' : 'Comments are closed'; + const msg = isZh ? '当前评论区已关闭' : 'Comments are closed'; $('#artalk-container').html(`
${msg}
`); } } else { - const msg = lang === 'zh' ? '当前评论区已关闭' : 'Comments are closed'; + const msg = isZh ? '当前评论区已关闭' : 'Comments are closed'; $('#artalk-container').html(`
${msg}
`); } }