dsh-plugin-greeting-bubble 1.2.1 → 1.3.0-beta.0

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
@@ -29,7 +29,10 @@
29
29
  ## 效果
30
30
 
31
31
  - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
32
- - **第二行显示账号余额**:`余额 ¥12.34(赠送 ¥3.00)`,来自当前登录的 DeepSeek 账号(充值 + 赠送钱包);每 60 秒刷新一次,**点余额这一行可立即刷新**。
32
+ - **第二行显示账号余额**:`余额 ¥12.34`,来自当前登录的 DeepSeek 账号;每 60 秒刷新一次。
33
+ - **余额低于 3 元**时,这一行变橙并显示「余额不足」提醒。
34
+ - **点余额这一行展开详情**:账户名/联系方式、充值余额、赠送余额、最近更新时间、插件版本,以及「用量」「充值」快捷入口;再点一次收起。
35
+ - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
33
36
  - 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
34
37
  - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
35
38
  - **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
@@ -89,7 +92,10 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
89
92
  | --- | --- |
90
93
  | 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
91
94
  | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
92
- | **点余额那一行** | 立即刷新余额(不用等 60 秒) |
95
+ | **点余额那一行** | 展开/收起详情(账户、钱包明细、更新时间、版本、快捷入口) |
96
+ | 详情里的「刷新」 | 立即刷新余额(不用等 60 秒) |
97
+ | 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
98
+ | 余额低于 ¥3 | 余额行变橙并显示「余额不足」 |
93
99
  | 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
94
100
  | 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
95
101
  | 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
@@ -149,7 +155,22 @@ const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
149
155
  - 点击余额那一行会立即刷新并重置退避;
150
156
  - 不建议改到 30 秒以下:余额接口是账号接口,不适合高频轮询。
151
157
 
152
- ### 5. 改成“只问候一次”(可选)
158
+ ### 5. 改提醒阈值 / 隐私默认值
159
+
160
+ `client.js` 顶部:
161
+
162
+ ```js
163
+ const LOW_BALANCE_CNY = 3; // 低于这个金额显示“余额不足”
164
+ const PLUGIN_VERSION = '1.3.0'; // 每次发版同步修改
165
+ ```
166
+
167
+ 隐私模式的状态保存在 localStorage 的 `dsh-greeting-bubble:privacy:v1`;想强制恢复“显示金额”,在控制台执行:
168
+
169
+ ```js
170
+ localStorage.removeItem('dsh-greeting-bubble:privacy:v1')
171
+ ```
172
+
173
+ ### 6. 改成“只问候一次”(可选)
153
174
 
154
175
  默认每次页面加载都会出现。如果希望用户关闭后永久不再出现,在组件里加一个 `localStorage` 开关,例如:
155
176
 
@@ -170,7 +191,7 @@ function GreetingBubble({ t }) {
170
191
 
171
192
  清除 `localStorage` 里这个键即可让问候重新出现。
172
193
 
173
- ### 6. 改图标、名称、描述
194
+ ### 7. 改图标、名称、描述
174
195
 
175
196
  - 图标:`icon.svg`(36×36,纯几何、无文字);
176
197
  - 插件页显示的名称与说明:`locale/zh.json`、`locale/en.json` 的 `meta.title` / `meta.description`;
package/client.js CHANGED
@@ -12,10 +12,14 @@
12
12
  * control. Registering a fresh `id` adds an entry beside the shipped ones
13
13
  * instead of replacing them.
14
14
  *
15
- * The bubble is draggable (pointer capture, viewport clamp, remembered in
16
- * localStorage) and shows the signed-in account's wallet balance, which it
17
- * reads through the Host's `account` Remote — the browser never sees the
18
- * account token and never calls Platform directly.
15
+ * Features:
16
+ * - draggable, viewport-clamped, position remembered in localStorage;
17
+ * - account balance from the Host `account` Remote (never the token itself),
18
+ * refreshed every 60s while visible, with backoff and a manual refresh;
19
+ * - privacy mode hides amounts (remembered);
20
+ * - a low-balance warning below 3 CNY;
21
+ * - an expandable details panel with wallets, account, update time, version,
22
+ * and links to the Platform usage/top-up pages.
19
23
  */
20
24
  window.__ModuleLoader__.load({
21
25
  id: 'dsh-plugin-greeting-bubble',
@@ -26,13 +30,26 @@ window.__ModuleLoader__.load({
26
30
  /** Locale namespace owned by this plugin (registered in `apply`). */
27
31
  const NS = 'greetingBubble';
28
32
 
33
+ /** Keep in sync with package.json's version on every release. */
34
+ const PLUGIN_VERSION = '1.3.0';
35
+
29
36
  /** Where the reader last dropped the bubble, as viewport px. */
30
37
  const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
31
38
 
32
- /** Normal refresh cadence while the page is visible, and the failure cap. */
39
+ /** Whether amounts are hidden. */
40
+ const PRIVACY_KEY = 'dsh-greeting-bubble:privacy:v1';
41
+
42
+ /** Refresh cadence while visible, and the cap after repeated failures. */
33
43
  const BALANCE_REFRESH_MS = 60_000;
34
44
  const BALANCE_MAX_BACKOFF_MS = 300_000;
35
45
 
46
+ /** Below this CNY amount the bubble warns. */
47
+ const LOW_BALANCE_CNY = 3;
48
+
49
+ /** Platform pages linked from the details panel. */
50
+ const USAGE_URL = 'https://platform.deepseek.com/usage';
51
+ const TOP_UP_URL = 'https://platform.deepseek.com/top_up';
52
+
36
53
  /** Read the remembered spot; a corrupt or absent value means "default". */
37
54
  function readPosition() {
38
55
  try {
@@ -57,6 +74,24 @@ window.__ModuleLoader__.load({
57
74
  }
58
75
  }
59
76
 
77
+ /** Read the privacy preference. */
78
+ function readPrivacy() {
79
+ try {
80
+ return window.localStorage.getItem(PRIVACY_KEY) === '1';
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+
86
+ /** Persist the privacy preference. */
87
+ function writePrivacy(hidden) {
88
+ try {
89
+ window.localStorage.setItem(PRIVACY_KEY, hidden ? '1' : '0');
90
+ } catch {
91
+ // Storage unavailable: the toggle applies to this view only.
92
+ }
93
+ }
94
+
60
95
  /** Keep a value inside [min, max], tolerating a viewport smaller than the card. */
61
96
  function clamp(value, min, max) {
62
97
  return Math.max(min, Math.min(value, Math.max(min, max)));
@@ -80,28 +115,37 @@ window.__ModuleLoader__.load({
80
115
  return Number.isFinite(amount) ? AMOUNT_FORMAT.format(amount) : value;
81
116
  }
82
117
 
83
- /** True when a wallet amount is exactly zero (Platform sends decimal strings). */
84
- function isZeroAmount(value) {
85
- return Number(value) === 0;
118
+ /** Format a wallet list, e.g. "¥11.77 / $1.00"; null when empty. */
119
+ function formatWallets(wallets) {
120
+ if (!Array.isArray(wallets) || wallets.length === 0) return null;
121
+ return wallets
122
+ .filter((wallet) => wallet && typeof wallet.balance === 'string')
123
+ .map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance))
124
+ .join(' / ') || null;
86
125
  }
87
126
 
88
- /**
89
- * Turn one `getBalance` result into the amount text for the second bubble
90
- * line, or null when nothing sensible can be shown (signed out, failed, or
91
- * empty wallets). The caller adds the localized "balance" label.
92
- * @param balance - `AccountDetails['balance']` or null.
93
- * @param bonusLabel - localized "bonus" word.
94
- */
95
- function formatBalance(balance, bonusLabel) {
127
+ /** Normalize the Remote balance result into displayable wallets. */
128
+ function normalizeBalance(balance) {
96
129
  if (!balance || balance.status !== 'ready' || !Array.isArray(balance.value)) return null;
97
- const normal = balance.value
98
- .filter((wallet) => wallet && typeof wallet.balance === 'string')
99
- .map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
130
+ const normal = balance.value.filter((wallet) => wallet && typeof wallet.balance === 'string');
100
131
  if (normal.length === 0) return null;
101
- const bonus = (balance.bonusWallets ?? [])
102
- .filter((wallet) => wallet && typeof wallet.balance === 'string' && !isZeroAmount(wallet.balance))
103
- .map((wallet) => currencySymbol(wallet.currency) + formatAmount(wallet.balance));
104
- return bonus.length === 0 ? normal.join(' / ') : normal.join(' / ') + '(' + bonusLabel + ' ' + bonus.join(' / ') + ')';
132
+ const bonus = (balance.bonusWallets ?? []).filter(
133
+ (wallet) => wallet && typeof wallet.balance === 'string' && Number(wallet.balance) !== 0,
134
+ );
135
+ return { normal, bonus };
136
+ }
137
+
138
+ /** True when any CNY wallet is below the warning threshold. */
139
+ function isLowBalance(normal) {
140
+ return (normal ?? []).some(
141
+ (wallet) => wallet.currency === 'CNY' && Number(wallet.balance) < LOW_BALANCE_CNY,
142
+ );
143
+ }
144
+
145
+ /** Local HH:MM:SS for the last successful refresh. */
146
+ function formatTime(timestamp) {
147
+ if (typeof timestamp !== 'number') return '--';
148
+ return new Date(timestamp).toLocaleTimeString();
105
149
  }
106
150
 
107
151
  /**
@@ -124,7 +168,7 @@ window.__ModuleLoader__.load({
124
168
  align-items: stretch;
125
169
  gap: 2px;
126
170
  box-sizing: border-box;
127
- max-width: min(340px, calc(100vw - 40px));
171
+ max-width: min(380px, calc(100vw - 40px));
128
172
  padding: 8px 6px 8px 12px;
129
173
  border: 0;
130
174
  --dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
@@ -158,7 +202,30 @@ window.__ModuleLoader__.load({
158
202
  min-width: 0;
159
203
  overflow-wrap: anywhere;
160
204
  }
161
- .dsh-greeting-balance {
205
+ .dsh-greeting-close {
206
+ flex: none;
207
+ display: inline-flex;
208
+ align-items: center;
209
+ justify-content: center;
210
+ width: 26px;
211
+ height: 26px;
212
+ margin-left: auto;
213
+ padding: 0;
214
+ border: 0;
215
+ border-radius: var(--dsw-radius-sm, 8px);
216
+ background: transparent;
217
+ color: var(--dsw-alias-label-tertiary);
218
+ cursor: pointer;
219
+ pointer-events: auto;
220
+ }
221
+ .dsh-greeting-close:hover {
222
+ background: var(--dsw-alias-interactive-bg-hover);
223
+ color: var(--dsw-alias-label-secondary);
224
+ }
225
+ .dsh-greeting-toggle {
226
+ display: flex;
227
+ align-items: center;
228
+ gap: 6px;
162
229
  margin: 0;
163
230
  padding: 0 0 0 24px;
164
231
  border: 0;
@@ -171,38 +238,78 @@ window.__ModuleLoader__.load({
171
238
  text-align: left;
172
239
  width: fit-content;
173
240
  max-width: 100%;
174
- overflow-wrap: anywhere;
175
241
  cursor: pointer;
176
242
  pointer-events: auto;
177
243
  }
178
- .dsh-greeting-balance:hover {
244
+ .dsh-greeting-toggle:hover {
179
245
  color: var(--dsw-alias-label-secondary);
180
246
  }
181
- .dsh-greeting-balance:focus-visible {
182
- outline: var(--dsw-focus-ring-width, 2px) solid
183
- var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
184
- outline-offset: 1px;
247
+ .dsh-greeting-toggle[data-low] {
248
+ color: var(--dsw-alias-state-warn-primary, #b26a00);
185
249
  }
186
- .dsh-greeting-close {
250
+ .dsh-greeting-chevron {
251
+ display: inline-block;
252
+ transition: transform 120ms ease;
253
+ }
254
+ .dsh-greeting-toggle[aria-expanded='true'] .dsh-greeting-chevron {
255
+ transform: rotate(90deg);
256
+ }
257
+ .dsh-greeting-warn {
187
258
  flex: none;
188
- display: inline-flex;
189
- align-items: center;
190
- justify-content: center;
191
- width: 26px;
192
- height: 26px;
193
- margin-left: auto;
259
+ padding: 0 5px;
260
+ border-radius: 999px;
261
+ background: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #b26a00) 14%, transparent);
262
+ font-size: 11px;
263
+ line-height: 16px;
264
+ }
265
+ .dsh-greeting-details {
266
+ display: flex;
267
+ flex-direction: column;
268
+ gap: 3px;
269
+ margin-top: 4px;
270
+ padding: 6px 6px 2px 24px;
271
+ border-top: 0.5px solid var(--dsw-alias-border-l3);
272
+ color: var(--dsw-alias-label-secondary);
273
+ font-size: 12px;
274
+ line-height: 17px;
275
+ cursor: default;
276
+ }
277
+ .dsh-greeting-row {
278
+ display: flex;
279
+ gap: 6px;
280
+ min-width: 0;
281
+ }
282
+ .dsh-greeting-row-label {
283
+ flex: none;
284
+ color: var(--dsw-alias-label-tertiary);
285
+ }
286
+ .dsh-greeting-row-value {
287
+ min-width: 0;
288
+ overflow-wrap: anywhere;
289
+ color: var(--dsw-alias-label-secondary);
290
+ }
291
+ .dsh-greeting-actions {
292
+ display: flex;
293
+ flex-wrap: wrap;
294
+ gap: 8px;
295
+ margin-top: 3px;
296
+ }
297
+ .dsh-greeting-action {
194
298
  padding: 0;
195
299
  border: 0;
196
- border-radius: var(--dsw-radius-sm, 8px);
197
300
  background: transparent;
198
- color: var(--dsw-alias-label-tertiary);
301
+ color: var(--dsw-alias-state-business-primary, #3b6fe0);
302
+ font: inherit;
303
+ font-size: 12px;
304
+ line-height: 17px;
199
305
  cursor: pointer;
200
- pointer-events: auto;
306
+ text-decoration: none;
201
307
  }
202
- .dsh-greeting-close:hover {
203
- background: var(--dsw-alias-interactive-bg-hover);
204
- color: var(--dsw-alias-label-secondary);
308
+ .dsh-greeting-action:hover {
309
+ text-decoration: underline;
205
310
  }
311
+ .dsh-greeting-action:focus-visible,
312
+ .dsh-greeting-toggle:focus-visible,
206
313
  .dsh-greeting-close:focus-visible {
207
314
  outline: var(--dsw-focus-ring-width, 2px) solid
208
315
  var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
@@ -228,24 +335,29 @@ window.__ModuleLoader__.load({
228
335
  /**
229
336
  * The greeting bubble itself.
230
337
  *
231
- * @param props - the framework `t` seat plus the injected balance loader.
338
+ * @param props - the framework `t` seat plus injected balance/profile loaders.
232
339
  * @returns the bubble, or null once the reader dismissed it.
233
340
  */
234
- function GreetingBubble({ t, loadBalance }) {
341
+ function GreetingBubble({ t, loadBalance, loadProfile }) {
235
342
  const [dismissed, setDismissed] = React.useState(false);
236
343
  const [position, setPosition] = React.useState(readPosition);
237
344
  const [dragging, setDragging] = React.useState(false);
238
- const [walletText, setWalletText] = React.useState(null);
345
+ const [balance, setBalance] = React.useState(null);
346
+ const [profile, setProfile] = React.useState(null);
347
+ const [updatedAt, setUpdatedAt] = React.useState(null);
348
+ const [expanded, setExpanded] = React.useState(false);
349
+ const [privacy, setPrivacy] = React.useState(readPrivacy);
239
350
  const bubbleRef = React.useRef(null);
240
351
  const dragRef = React.useRef(null);
241
352
  const inFlightRef = React.useRef(null);
353
+ const profileRef = React.useRef(null);
242
354
  const timerRef = React.useRef(null);
243
355
  const backoffRef = React.useRef(BALANCE_REFRESH_MS);
244
356
  const cancelledRef = React.useRef(false);
245
357
 
246
358
  const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback);
247
359
 
248
- /** Fetch once, deduplicating concurrent calls; resolves to wallet text or null. */
360
+ /** Fetch once, deduplicating concurrent calls. */
249
361
  function readBalance() {
250
362
  if (typeof loadBalance !== 'function') return Promise.resolve(null);
251
363
  if (inFlightRef.current !== null) return inFlightRef.current;
@@ -253,7 +365,8 @@ window.__ModuleLoader__.load({
253
365
  .then(() => loadBalance())
254
366
  .then((result) => {
255
367
  if (!result || result.ok !== true) return null;
256
- return formatBalance(result.value, label('bonus', '赠送'));
368
+ const wallets = normalizeBalance(result.value);
369
+ return wallets === null ? null : { wallets, at: Date.now() };
257
370
  })
258
371
  .catch(() => null)
259
372
  .finally(() => { inFlightRef.current = null; });
@@ -261,6 +374,24 @@ window.__ModuleLoader__.load({
261
374
  return run;
262
375
  }
263
376
 
377
+ /** Profile is read on demand (first expand) and cached for the page view. */
378
+ function readProfile() {
379
+ if (profileRef.current !== null) return Promise.resolve(profileRef.current);
380
+ if (typeof loadProfile !== 'function') return Promise.resolve(null);
381
+ const run = Promise.resolve()
382
+ .then(() => loadProfile())
383
+ .then((result) => {
384
+ if (!result || result.ok !== true) return null;
385
+ const value = result.value;
386
+ if (!value || value.status !== 'ready' || !value.value) return null;
387
+ const next = { name: value.value.name, contact: value.value.contact };
388
+ profileRef.current = next;
389
+ return next;
390
+ })
391
+ .catch(() => null);
392
+ return run;
393
+ }
394
+
264
395
  /** One polling cycle: refresh, then schedule the next attempt with backoff. */
265
396
  function tick() {
266
397
  if (cancelledRef.current) return;
@@ -269,10 +400,13 @@ window.__ModuleLoader__.load({
269
400
  timerRef.current = window.setTimeout(tick, BALANCE_REFRESH_MS);
270
401
  return;
271
402
  }
272
- void readBalance().then((text) => {
403
+ void readBalance().then((result) => {
273
404
  if (cancelledRef.current) return;
274
- setWalletText(text);
275
- backoffRef.current = text === null
405
+ if (result !== null) {
406
+ setBalance(result.wallets);
407
+ setUpdatedAt(result.at);
408
+ }
409
+ backoffRef.current = result === null
276
410
  ? Math.min(backoffRef.current * 2, BALANCE_MAX_BACKOFF_MS)
277
411
  : BALANCE_REFRESH_MS;
278
412
  timerRef.current = window.setTimeout(tick, backoffRef.current);
@@ -296,7 +430,7 @@ window.__ModuleLoader__.load({
296
430
  if (timerRef.current !== null) window.clearTimeout(timerRef.current);
297
431
  document.removeEventListener('visibilitychange', handleVisibility);
298
432
  };
299
- // The loader is stable for the registration's lifetime.
433
+ // The loaders are stable for the registration's lifetime.
300
434
  // eslint-disable-next-line react-hooks/exhaustive-deps
301
435
  }, []);
302
436
 
@@ -316,23 +450,54 @@ window.__ModuleLoader__.load({
316
450
  }, []);
317
451
 
318
452
  if (dismissed) return null;
319
- const text = label('greeting', '你好,腾盛');
453
+ const greeting = label('greeting', '你好,腾盛');
320
454
  const dismissLabel = label('dismiss', '关闭问候气泡');
321
- const balanceLine = label('balance', '余额') + ' ' + (walletText ?? label('unavailable', '--'));
455
+ const normalText = balance === null ? null : formatWallets(balance.normal);
456
+ const bonusText = balance === null ? null : formatWallets(balance.bonus);
457
+ const low = balance !== null && isLowBalance(balance.normal);
458
+ const amountText = privacy
459
+ ? label('hidden', '••••')
460
+ : (normalText ?? label('unavailable', '--'));
461
+ const accountText = profile && (profile.name || profile.contact)
462
+ ? [profile.name, profile.contact].filter(Boolean).join(' · ')
463
+ : label('unavailable', '--');
322
464
 
323
- /** Manual refresh: reset the backoff and read once. */
324
- function handleBalanceClick(event) {
325
- event.stopPropagation();
465
+ /** Refresh now and reset the backoff. */
466
+ function handleRefresh() {
326
467
  backoffRef.current = BALANCE_REFRESH_MS;
327
- void readBalance().then((value) => {
328
- if (!cancelledRef.current) setWalletText(value);
468
+ void readBalance().then((result) => {
469
+ if (cancelledRef.current || result === null) return;
470
+ setBalance(result.wallets);
471
+ setUpdatedAt(result.at);
472
+ });
473
+ }
474
+
475
+ /** Expand/collapse; the first expansion loads the account profile. */
476
+ function handleToggle() {
477
+ setExpanded((current) => {
478
+ const next = !current;
479
+ if (next && profile === null) {
480
+ void readProfile().then((value) => {
481
+ if (!cancelledRef.current && value !== null) setProfile(value);
482
+ });
483
+ }
484
+ return next;
485
+ });
486
+ }
487
+
488
+ /** Toggle the amount mask and remember it. */
489
+ function handlePrivacy() {
490
+ setPrivacy((current) => {
491
+ const next = !current;
492
+ writePrivacy(next);
493
+ return next;
329
494
  });
330
495
  }
331
496
 
332
497
  /** Start a drag: switch to absolute coordinates and capture the pointer. */
333
498
  function handlePointerDown(event) {
334
499
  if (event.button !== undefined && event.button !== 0) return;
335
- if (event.target && event.target.closest && event.target.closest('button')) return;
500
+ if (event.target && event.target.closest && event.target.closest('button, a')) return;
336
501
  const element = bubbleRef.current;
337
502
  if (!element) return;
338
503
  const rect = element.getBoundingClientRect();
@@ -405,10 +570,7 @@ window.__ModuleLoader__.load({
405
570
  'div',
406
571
  { className: 'dsh-greeting-main', key: 'main' },
407
572
  h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
408
- // `lang` pins the reading voice for this fixed Chinese phrase; the
409
- // status role lives on the text so the controls stay outside the
410
- // live region.
411
- h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, text),
573
+ h('span', { className: 'dsh-greeting-text', role: 'status', lang: 'zh-CN' }, greeting),
412
574
  h(
413
575
  'button',
414
576
  {
@@ -434,14 +596,66 @@ window.__ModuleLoader__.load({
434
596
  h(
435
597
  'button',
436
598
  {
437
- key: 'balance',
438
- className: 'dsh-greeting-balance',
599
+ key: 'toggle',
600
+ className: 'dsh-greeting-toggle',
439
601
  type: 'button',
440
- title: label('refreshBalance', '刷新余额'),
441
- onClick: handleBalanceClick,
602
+ 'data-low': low ? '' : undefined,
603
+ 'aria-expanded': expanded ? 'true' : 'false',
604
+ title: label('details', '展开详情'),
605
+ onClick: handleToggle,
442
606
  },
443
- balanceLine,
607
+ h('span', { className: 'dsh-greeting-chevron', 'aria-hidden': 'true' }, '▸'),
608
+ h('span', null, label('balance', '余额') + ' ' + amountText),
609
+ low
610
+ ? h('span', { className: 'dsh-greeting-warn' }, label('lowBalance', '余额不足'))
611
+ : null,
444
612
  ),
613
+ expanded
614
+ ? h(
615
+ 'div',
616
+ { className: 'dsh-greeting-details', key: 'details' },
617
+ h(
618
+ 'div',
619
+ { className: 'dsh-greeting-row' },
620
+ h('span', { className: 'dsh-greeting-row-label' }, label('account', '账户')),
621
+ h('span', { className: 'dsh-greeting-row-value' }, accountText),
622
+ ),
623
+ h(
624
+ 'div',
625
+ { className: 'dsh-greeting-row' },
626
+ h('span', { className: 'dsh-greeting-row-label' }, label('topUpBalance', '充值')),
627
+ h('span', { className: 'dsh-greeting-row-value' }, privacy ? label('hidden', '••••') : (normalText ?? label('unavailable', '--'))),
628
+ ),
629
+ h(
630
+ 'div',
631
+ { className: 'dsh-greeting-row' },
632
+ h('span', { className: 'dsh-greeting-row-label' }, label('bonusBalance', '赠送')),
633
+ h('span', { className: 'dsh-greeting-row-value' }, privacy ? label('hidden', '••••') : (bonusText ?? label('unavailable', '--'))),
634
+ ),
635
+ h(
636
+ 'div',
637
+ { className: 'dsh-greeting-row' },
638
+ h('span', { className: 'dsh-greeting-row-label' }, label('updated', '更新')),
639
+ h('span', { className: 'dsh-greeting-row-value' }, formatTime(updatedAt) + ' · v' + PLUGIN_VERSION),
640
+ ),
641
+ h(
642
+ 'div',
643
+ { className: 'dsh-greeting-actions' },
644
+ h(
645
+ 'button',
646
+ { className: 'dsh-greeting-action', type: 'button', onClick: handleRefresh },
647
+ label('refresh', '刷新'),
648
+ ),
649
+ h(
650
+ 'button',
651
+ { className: 'dsh-greeting-action', type: 'button', onClick: handlePrivacy },
652
+ privacy ? label('showAmount', '显示金额') : label('hideAmount', '隐藏金额'),
653
+ ),
654
+ h('a', { className: 'dsh-greeting-action', href: USAGE_URL, target: '_blank', rel: 'noreferrer' }, label('usage', '用量')),
655
+ h('a', { className: 'dsh-greeting-action', href: TOP_UP_URL, target: '_blank', rel: 'noreferrer' }, label('topUp', '充值')),
656
+ ),
657
+ )
658
+ : null,
445
659
  ),
446
660
  );
447
661
  }
@@ -462,16 +676,38 @@ window.__ModuleLoader__.load({
462
676
  dismiss: '关闭问候气泡',
463
677
  balance: '余额',
464
678
  bonus: '赠送',
679
+ topUpBalance: '充值',
680
+ bonusBalance: '赠送',
681
+ account: '账户',
682
+ updated: '更新',
683
+ hidden: '••••',
465
684
  unavailable: '--',
466
- refreshBalance: '刷新余额',
685
+ lowBalance: '余额不足',
686
+ details: '展开详情',
687
+ refresh: '刷新',
688
+ hideAmount: '隐藏金额',
689
+ showAmount: '显示金额',
690
+ usage: '用量',
691
+ topUp: '充值',
467
692
  },
468
693
  en: {
469
694
  greeting: '你好,腾盛',
470
695
  dismiss: 'Dismiss greeting',
471
696
  balance: 'Balance',
472
697
  bonus: 'Bonus',
698
+ topUpBalance: 'Top-up',
699
+ bonusBalance: 'Bonus',
700
+ account: 'Account',
701
+ updated: 'Updated',
702
+ hidden: '••••',
473
703
  unavailable: '--',
474
- refreshBalance: 'Refresh balance',
704
+ lowBalance: 'Low balance',
705
+ details: 'Show details',
706
+ refresh: 'Refresh',
707
+ hideAmount: 'Hide amounts',
708
+ showAmount: 'Show amounts',
709
+ usage: 'Usage',
710
+ topUp: 'Top up',
475
711
  },
476
712
  }),
477
713
  'greeting-bubble: dictionaries',
@@ -490,19 +726,27 @@ window.__ModuleLoader__.load({
490
726
  timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
491
727
  };
492
728
  };
493
- const loadBalance = () => {
729
+ const accountRemote = () => {
494
730
  const account = ctx.remote && ctx.remote.account;
495
- if (!account || typeof account.getBalance !== 'function') {
496
- throw new Error('account service unavailable');
497
- }
731
+ if (!account) throw new Error('account service unavailable');
732
+ return account;
733
+ };
734
+ const loadBalance = () => {
735
+ const account = accountRemote();
736
+ if (typeof account.getBalance !== 'function') throw new Error('balance unavailable');
498
737
  return account.getBalance(metadata());
499
738
  };
739
+ const loadProfile = () => {
740
+ const account = accountRemote();
741
+ if (typeof account.getProfile !== 'function') throw new Error('profile unavailable');
742
+ return account.getProfile(metadata());
743
+ };
500
744
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({
501
745
  name: 'shell.overlay',
502
746
  id: 'greeting-bubble',
503
747
  order: 50,
504
748
  locale: NS,
505
- inject: () => ({ loadBalance }),
749
+ inject: () => ({ loadBalance, loadProfile }),
506
750
  }, GreetingBubble));
507
751
  },
508
752
  };
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, plus the signed-in DeepSeek account balance (top-up and bonus wallets) refreshed every 60 seconds; click the balance line to refresh it immediately. Drag the bubble anywhere; its position is remembered for the next visit. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only control labels are localized. Balance is read through the DSH account service, so the browser never sees the account token; a signed-out or failed read shows “Balance --”. 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 “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, plus the signed-in DeepSeek account balance (top-up and bonus wallets) refreshed every 60 seconds. A balance below 3 CNY is flagged. Click the balance line to expand details: account, 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. The greeting stays Chinese in every interface language; only control labels are localized. 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 秒刷新一次,点击余额行可立即刷新。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 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.2.1",
3
+ "version": "1.3.0-beta.0",
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": {