From 9d1884cf201d35a8d81a13cb6fdfba548d5585b1 Mon Sep 17 00:00:00 2001 From: yuez Date: Sun, 20 Sep 2026 15:25:29 +0800 Subject: [PATCH] feat(quota): All tab Command Code card shows Plan + 5h/weekly/monthly windows with reset times (v0.4.4) --- plugin/management_test.go | 4 ++-- plugin/plugin.go | 2 +- plugin/quota_page.go | 41 ++++++++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/plugin/management_test.go b/plugin/management_test.go index 6876be8..60f0ff1 100644 --- a/plugin/management_test.go +++ b/plugin/management_test.go @@ -74,8 +74,8 @@ func TestHandleManagement_QuotaResource(t *testing.T) { if !strings.Contains(bodyStr, "用量配额") { t.Errorf("Body does not contain expected menu text 用量配额") } - if !strings.Contains(bodyStr, "v0.4.3") { - t.Errorf("Body does not contain version badge v0.4.3") + if !strings.Contains(bodyStr, "v0.4.4") { + t.Errorf("Body does not contain version badge v0.4.4") } } } diff --git a/plugin/plugin.go b/plugin/plugin.go index 292aed0..36b9f0b 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -13,7 +13,7 @@ import ( const ( PluginID = "commandcode" PluginName = "commandcode" - PluginVersion = "0.4.3" + PluginVersion = "0.4.4" PluginAuthor = "zgs225" PluginRepo = "https://github.com/zgs225/cliproxy-plugin-commandcode" PluginLogo = "https://raw.githubusercontent.com/zgs225/cliproxy-plugin-commandcode/main/assets/logo.svg" diff --git a/plugin/quota_page.go b/plugin/quota_page.go index cd9dea7..172656b 100644 --- a/plugin/quota_page.go +++ b/plugin/quota_page.go @@ -918,7 +918,7 @@ const QuotaPageHTML = `
用量配额 - v0.4.3 + v0.4.4
@@ -1625,12 +1625,43 @@ const QuotaPageHTML = ` }); allBadgeCommandcode.className = "status-badge " + badgeVisualClass(cc.level); allBadgeTextCommandcode.textContent = BADGE_TEXT[cc.level] || "-"; + // Plan + 三个限额窗口(百分比/进度条/重置时间),行结构与 OpenCode 卡片一致, + // 倒计时走 data-reset-at/data-reset-secs 属性,由 updateTimers() 统一刷新 + const ccWins = [ + { name: "Rolling 5h", o: limits.five_hour || {} }, + { name: "Weekly", o: limits.weekly || {} }, + { name: "Monthly", o: limits.monthly || {} } + ]; + let ccRows = ""; + ccWins.forEach(function (d) { + const w = d.o; + const pct = clampPercent(w.percentage); + const level = levelOf(pct, w.exceeded, ""); + let resetAt = ""; + let resetSecs = ""; + if (w.reset_at) { + const t = new Date(w.reset_at); + if (!isNaN(t.getTime())) resetAt = t.toISOString(); + } + if (!resetAt && w.reset_in_seconds > 0) { + resetSecs = String(w.reset_in_seconds); + } + const resetAttr = resetAt + ? " data-reset-at=\"" + esc(resetAt) + "\"" + : (resetSecs ? " data-reset-secs=\"" + esc(resetSecs) + "\"" : ""); + const pctText = pct === null ? "-" : Math.round(pct) + "%"; + const pctCls = level === "exceeded" ? " bad" : pct !== null && pct >= 80 ? " warn" : ""; + const barCls = level === "exceeded" ? " danger" : level === "warning" ? " warning" : ""; + ccRows += '
' + + '' + d.name + '' + + '
' + + '' + pctText + '' + + '-' + + '
'; + }); allBodyCommandcode.innerHTML = summaryRow("Plan", esc(planName)) + - summaryRow("Total Credits", formatUSD(credits.total_credits)) + - summaryRow("Monthly Credits", formatUSD(credits.monthly_credits)) + - summaryRow("最差窗口", esc(worstName) + " " + (worstPct === null ? "-" : worstPct.toFixed(1) + "%")) + - miniBar(worstPct, worstLevel); + '
' + ccRows + '
'; } else { allBadgeCommandcode.className = "status-badge"; allBadgeTextCommandcode.textContent = "尚未加载";