dsh-plugin-greeting-bubble 1.4.0-beta.0 → 1.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/client.js +46 -11
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
- **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
|
|
33
33
|
- **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
|
|
34
34
|
- **点余额这一行展开详情**:账户名/联系方式、**当前会话标题与模型**、**连接状态(断开时可一键重连)**、**今日消耗估算(标注“估算”)**、充值余额、赠送余额、最近更新时间、插件版本,以及「用量」「充值」快捷入口;再点一次收起。
|
|
35
|
+
- 今日估算的基准:优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费;详情里会显示基准时间。
|
|
35
36
|
- 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
|
|
36
37
|
- 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
|
|
37
38
|
- 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
|
package/client.js
CHANGED
|
@@ -157,28 +157,59 @@ window.__ModuleLoader__.load({
|
|
|
157
157
|
return now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0');
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Estimated CNY spent today, measured from the closest known day-start
|
|
162
|
+
* balance: yesterday's last reading across midnight when available,
|
|
163
|
+
* otherwise today's first reading. A top-up raises the baseline so it does
|
|
164
|
+
* not count as negative spending.
|
|
165
|
+
* @param normal - current normal wallets.
|
|
166
|
+
* @returns `{ spent, startAt }`, or null when no CNY wallet is present.
|
|
167
|
+
*/
|
|
161
168
|
function trackConsumption(normal) {
|
|
162
169
|
const cny = (normal ?? []).find((wallet) => wallet.currency === 'CNY' && typeof wallet.balance === 'string');
|
|
163
170
|
if (!cny) return null;
|
|
164
171
|
const amount = Number(cny.balance);
|
|
165
172
|
if (!Number.isFinite(amount)) return null;
|
|
166
173
|
const today = localDateKey();
|
|
167
|
-
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
let state = null;
|
|
168
176
|
try {
|
|
169
|
-
|
|
177
|
+
state = JSON.parse(window.localStorage.getItem(CONSUMPTION_KEY) || 'null');
|
|
170
178
|
} catch {
|
|
171
|
-
|
|
179
|
+
state = null;
|
|
180
|
+
}
|
|
181
|
+
let baseline;
|
|
182
|
+
let startAt;
|
|
183
|
+
if (state && state.date === today && typeof state.baseline === 'number') {
|
|
184
|
+
baseline = state.baseline;
|
|
185
|
+
startAt = typeof state.startAt === 'number' ? state.startAt : now;
|
|
186
|
+
if (typeof state.lastAmount === 'number' && amount > state.lastAmount) {
|
|
187
|
+
// A top-up mid-day: keep the spend counter continuous.
|
|
188
|
+
baseline += amount - state.lastAmount;
|
|
189
|
+
}
|
|
190
|
+
} else if (state && typeof state.lastAmount === 'number' && typeof state.lastAt === 'number'
|
|
191
|
+
&& localDateKey(new Date(state.lastAt)) !== today) {
|
|
192
|
+
// The plugin was running before midnight: its last reading is the
|
|
193
|
+
// closest available day-start balance.
|
|
194
|
+
baseline = state.lastAmount;
|
|
195
|
+
startAt = state.lastAt;
|
|
196
|
+
} else {
|
|
197
|
+
// No reading from before today: today's first reading is the baseline.
|
|
198
|
+
baseline = amount;
|
|
199
|
+
startAt = now;
|
|
172
200
|
}
|
|
173
|
-
let baseline = stored && stored.date === today && typeof stored.baseline === 'number' ? stored.baseline : amount;
|
|
174
|
-
if (amount > baseline) baseline = amount;
|
|
175
|
-
const spent = Math.max(0, baseline - amount);
|
|
176
201
|
try {
|
|
177
|
-
window.localStorage.setItem(CONSUMPTION_KEY, JSON.stringify({
|
|
202
|
+
window.localStorage.setItem(CONSUMPTION_KEY, JSON.stringify({
|
|
203
|
+
date: today,
|
|
204
|
+
baseline,
|
|
205
|
+
startAt,
|
|
206
|
+
lastAmount: amount,
|
|
207
|
+
lastAt: now,
|
|
208
|
+
}));
|
|
178
209
|
} catch {
|
|
179
210
|
// Storage unavailable: the estimate simply does not survive the reload.
|
|
180
211
|
}
|
|
181
|
-
return spent;
|
|
212
|
+
return { spent: Math.max(0, baseline - amount), startAt };
|
|
182
213
|
}
|
|
183
214
|
|
|
184
215
|
/** Greeting key by local hour. */
|
|
@@ -568,7 +599,9 @@ window.__ModuleLoader__.load({
|
|
|
568
599
|
: label('unavailable', '--');
|
|
569
600
|
const spentText = spent === null
|
|
570
601
|
? label('unavailable', '--')
|
|
571
|
-
: '≈ ' + currencySymbol('CNY') + formatAmount(spent)
|
|
602
|
+
: '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent) + ' '
|
|
603
|
+
+ label('estimate', '(估算)')
|
|
604
|
+
+ (typeof spent.startAt === 'number' ? ' · ' + label('baseline', '基准') + ' ' + formatTime(spent.startAt) : '');
|
|
572
605
|
|
|
573
606
|
/** Refresh now and reset the backoff. */
|
|
574
607
|
function handleRefresh() {
|
|
@@ -763,7 +796,7 @@ window.__ModuleLoader__.load({
|
|
|
763
796
|
'div',
|
|
764
797
|
{ className: 'dsh-greeting-row' },
|
|
765
798
|
h('span', { className: 'dsh-greeting-row-label' }, label('today', '今日')),
|
|
766
|
-
h('span', { className: 'dsh-greeting-row-value' }, spentText
|
|
799
|
+
h('span', { className: 'dsh-greeting-row-value' }, spentText),
|
|
767
800
|
),
|
|
768
801
|
h(
|
|
769
802
|
'div',
|
|
@@ -826,6 +859,7 @@ window.__ModuleLoader__.load({
|
|
|
826
859
|
updated: '更新',
|
|
827
860
|
today: '今日',
|
|
828
861
|
estimate: '(估算)',
|
|
862
|
+
baseline: '基准',
|
|
829
863
|
hidden: '••••',
|
|
830
864
|
unavailable: '--',
|
|
831
865
|
lowBalance: '余额不足',
|
|
@@ -857,6 +891,7 @@ window.__ModuleLoader__.load({
|
|
|
857
891
|
updated: 'Updated',
|
|
858
892
|
today: 'Today',
|
|
859
893
|
estimate: '(estimate)',
|
|
894
|
+
baseline: 'baseline',
|
|
860
895
|
hidden: '••••',
|
|
861
896
|
unavailable: '--',
|
|
862
897
|
lowBalance: 'Low balance',
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"description": "Shows a time-aware “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer (morning/noon/afternoon/evening variants), plus the signed-in DeepSeek account balance refreshed every 60 seconds. A balance below 3 CNY is flagged. Click the balance line to expand details: account, current session title and model, connection state with a one-click reconnect, today's spending estimate (
|
|
3
|
+
"description": "Shows a time-aware “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer (morning/noon/afternoon/evening variants), plus the signed-in DeepSeek account balance refreshed every 60 seconds. A balance below 3 CNY is flagged. Click the balance line to expand details: account, current session title and model, connection state with a one-click reconnect, today's spending estimate (marked as an estimate; baseline is the last balance seen yesterday or the first seen today, ignoring top-ups), wallet breakdown, last update, plugin version, and shortcuts to the Platform usage/top-up pages; a privacy toggle hides amounts, and drag remembers the bubble position. Click × to dismiss it; it appears again on the next page load. Control labels are localized; the greeting stays Chinese. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “--”. The plugin makes no network requests of its own and collects no data. Disable or remove the bundle under Plugins to remove it.",
|
|
4
4
|
"detail": "docs/DETAIL.md"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"description": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3
|
|
3
|
+
"description": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行展开详情:账户信息、当前会话标题与模型、连接状态(断开时可一键重连)、今日消耗估算(标注估算,基准取昨日最后一次或今日首次读到的余额,忽略充值)、充值/赠送明细、更新时间、插件版本,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
|
|
4
4
|
"detail": "docs/DETAIL.zh.md"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED