dsh-plugin-greeting-bubble 1.4.0-beta.0 → 1.4.0-beta.2

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 CHANGED
@@ -31,7 +31,8 @@
31
31
  - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 早上好/中午好/下午好/晚上好,腾盛 ×(按当前时间变化)
32
32
  - **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
33
33
  - **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
34
- - **点余额这一行展开详情**:账户名/联系方式、**当前会话标题与模型**、**连接状态(断开时可一键重连)**、**今日消耗估算(标注“估算”)**、充值余额、赠送余额、最近更新时间、插件版本,以及「用量」「充值」快捷入口;再点一次收起。
34
+ - **点余额这一行展开详情**:账户名/联系方式、**当前会话标题与模型**、**连接状态(断开时可一键重连)**、**今日消耗估算(标注“估算”)**、充值余额、赠送余额、最近更新时间,以及「用量」「充值」快捷入口;再点一次收起。
35
+ - 今日估算的基准:优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费;详情里会显示基准时间。
35
36
  - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
36
37
  - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
37
38
  - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
@@ -162,7 +163,6 @@ const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
162
163
 
163
164
  ```js
164
165
  const LOW_BALANCE_CNY = 3; // 低于这个金额显示“余额不足”
165
- const PLUGIN_VERSION = '1.3.0'; // 每次发版同步修改
166
166
  ```
167
167
 
168
168
  隐私模式的状态保存在 localStorage 的 `dsh-greeting-bubble:privacy:v1`;想强制恢复“显示金额”,在控制台执行:
package/client.js CHANGED
@@ -30,9 +30,6 @@ window.__ModuleLoader__.load({
30
30
  /** Locale namespace owned by this plugin (registered in `apply`). */
31
31
  const NS = 'greetingBubble';
32
32
 
33
- /** Keep in sync with package.json's version on every release. */
34
- const PLUGIN_VERSION = '1.3.0';
35
-
36
33
  /** Where the reader last dropped the bubble, as viewport px. */
37
34
  const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
38
35
 
@@ -157,28 +154,59 @@ window.__ModuleLoader__.load({
157
154
  return now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0');
158
155
  }
159
156
 
160
- /** Estimated CNY spent today, measured from the first balance this plugin saw today. */
157
+ /**
158
+ * Estimated CNY spent today, measured from the closest known day-start
159
+ * balance: yesterday's last reading across midnight when available,
160
+ * otherwise today's first reading. A top-up raises the baseline so it does
161
+ * not count as negative spending.
162
+ * @param normal - current normal wallets.
163
+ * @returns `{ spent, startAt }`, or null when no CNY wallet is present.
164
+ */
161
165
  function trackConsumption(normal) {
162
166
  const cny = (normal ?? []).find((wallet) => wallet.currency === 'CNY' && typeof wallet.balance === 'string');
163
167
  if (!cny) return null;
164
168
  const amount = Number(cny.balance);
165
169
  if (!Number.isFinite(amount)) return null;
166
170
  const today = localDateKey();
167
- let stored = null;
171
+ const now = Date.now();
172
+ let state = null;
168
173
  try {
169
- stored = JSON.parse(window.localStorage.getItem(CONSUMPTION_KEY) || 'null');
174
+ state = JSON.parse(window.localStorage.getItem(CONSUMPTION_KEY) || 'null');
170
175
  } catch {
171
- stored = null;
176
+ state = null;
177
+ }
178
+ let baseline;
179
+ let startAt;
180
+ if (state && state.date === today && typeof state.baseline === 'number') {
181
+ baseline = state.baseline;
182
+ startAt = typeof state.startAt === 'number' ? state.startAt : now;
183
+ if (typeof state.lastAmount === 'number' && amount > state.lastAmount) {
184
+ // A top-up mid-day: keep the spend counter continuous.
185
+ baseline += amount - state.lastAmount;
186
+ }
187
+ } else if (state && typeof state.lastAmount === 'number' && typeof state.lastAt === 'number'
188
+ && localDateKey(new Date(state.lastAt)) !== today) {
189
+ // The plugin was running before midnight: its last reading is the
190
+ // closest available day-start balance.
191
+ baseline = state.lastAmount;
192
+ startAt = state.lastAt;
193
+ } else {
194
+ // No reading from before today: today's first reading is the baseline.
195
+ baseline = amount;
196
+ startAt = now;
172
197
  }
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
198
  try {
177
- window.localStorage.setItem(CONSUMPTION_KEY, JSON.stringify({ date: today, baseline }));
199
+ window.localStorage.setItem(CONSUMPTION_KEY, JSON.stringify({
200
+ date: today,
201
+ baseline,
202
+ startAt,
203
+ lastAmount: amount,
204
+ lastAt: now,
205
+ }));
178
206
  } catch {
179
207
  // Storage unavailable: the estimate simply does not survive the reload.
180
208
  }
181
- return spent;
209
+ return { spent: Math.max(0, baseline - amount), startAt };
182
210
  }
183
211
 
184
212
  /** Greeting key by local hour. */
@@ -568,7 +596,9 @@ window.__ModuleLoader__.load({
568
596
  : label('unavailable', '--');
569
597
  const spentText = spent === null
570
598
  ? label('unavailable', '--')
571
- : '≈ ' + currencySymbol('CNY') + formatAmount(spent);
599
+ : '≈ ' + currencySymbol('CNY') + formatAmount(spent.spent) + ' '
600
+ + label('estimate', '(估算)')
601
+ + (typeof spent.startAt === 'number' ? ' · ' + label('baseline', '基准') + ' ' + formatTime(spent.startAt) : '');
572
602
 
573
603
  /** Refresh now and reset the backoff. */
574
604
  function handleRefresh() {
@@ -751,7 +781,7 @@ window.__ModuleLoader__.load({
751
781
  'div',
752
782
  { className: 'dsh-greeting-row' },
753
783
  h('span', { className: 'dsh-greeting-row-label' }, label('updated', '更新')),
754
- h('span', { className: 'dsh-greeting-row-value' }, formatTime(updatedAt) + ' · v' + PLUGIN_VERSION),
784
+ h('span', { className: 'dsh-greeting-row-value' }, formatTime(updatedAt)),
755
785
  ),
756
786
  h(
757
787
  'div',
@@ -763,7 +793,7 @@ window.__ModuleLoader__.load({
763
793
  'div',
764
794
  { className: 'dsh-greeting-row' },
765
795
  h('span', { className: 'dsh-greeting-row-label' }, label('today', '今日')),
766
- h('span', { className: 'dsh-greeting-row-value' }, spentText + ' ' + label('estimate', '(估算)')),
796
+ h('span', { className: 'dsh-greeting-row-value' }, spentText),
767
797
  ),
768
798
  h(
769
799
  'div',
@@ -826,6 +856,7 @@ window.__ModuleLoader__.load({
826
856
  updated: '更新',
827
857
  today: '今日',
828
858
  estimate: '(估算)',
859
+ baseline: '基准',
829
860
  hidden: '••••',
830
861
  unavailable: '--',
831
862
  lowBalance: '余额不足',
@@ -857,6 +888,7 @@ window.__ModuleLoader__.load({
857
888
  updated: 'Updated',
858
889
  today: 'Today',
859
890
  estimate: '(estimate)',
891
+ baseline: 'baseline',
860
892
  hidden: '••••',
861
893
  unavailable: '--',
862
894
  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 (explicitly marked as an estimate), 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.",
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, 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 元会显示提醒;点击余额行展开详情:账户信息、当前会话标题与模型、连接状态(断开时可一键重连)、今日消耗估算(明确标注估算)、充值/赠送明细、更新时间、插件版本,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
3
+ "description": "页面加载后,在窗口右下角、输入框上方弹出按时间变化的问候气泡(早上好/中午好/下午好/晚上好,腾盛),并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行展开详情:账户信息、当前会话标题与模型、连接状态(断开时可一键重连)、今日消耗估算(标注估算,基准取昨日最后一次或今日首次读到的余额,忽略充值)、充值/赠送明细、更新时间,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。界面文案跟随语言,问候语保持中文。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
4
4
  "detail": "docs/DETAIL.zh.md"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.4.0-beta.0",
3
+ "version": "1.4.0-beta.2",
4
4
  "description": "Shows a “你好,腾盛” speech bubble in the bottom-right corner of the DeepSeek Harness Web GUI.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {