dsh-plugin-greeting-bubble 1.2.0 → 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`;
@@ -227,6 +248,7 @@ dsh-plugin-greeting-bubble/
227
248
  ├─ docs/
228
249
  │ ├─ DETAIL.md # 英文详情页文档(只含一张特性图)
229
250
  │ ├─ DETAIL.zh.md # 中文详情页文档(同一张图,中文替代文本)
251
+ │ ├─ DEV.md # 维护者开发/发布/排错指南
230
252
  │ └─ preview.svg # 特性图(640×300,无文字)
231
253
  ├─ test/
232
254
  │ └─ smoke.mjs # 离线冒烟测试(不随包发布)
@@ -238,6 +260,8 @@ dsh-plugin-greeting-bubble/
238
260
 
239
261
  ## 本地开发与测试
240
262
 
263
+ 维护者请先看 **[docs/DEV.md](docs/DEV.md)**:里面记录了完整的开发、测试、Git 与 npm 发布流程,以及我们实际踩过的坑(模块缓存、安装残留、2FA、观察期、GitHub DNS 等)。
264
+
241
265
  ```powershell
242
266
  # 1. 语法检查(需要 Node.js 18+)
243
267
  node --check index.js
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/docs/DEV.md ADDED
@@ -0,0 +1,264 @@
1
+ # 开发与发布指南(维护者)
2
+
3
+ 这份文档面向仓库维护者,记录本插件的本地开发、测试、Git 提交和 npm 发布流程,以及我们实际踩过的坑。普通用户请看 [README](../README.md)。
4
+
5
+ 所有命令都在 **PowerShell** 中执行,工作目录为仓库根目录(本文以 `D:\插件实现` 为例)。
6
+
7
+ ---
8
+
9
+ ## 0. 环境说明
10
+
11
+ 本机没有全局 `node`/`npm`,但 DSH 自带了一套 Node 和 pnpm,后面的命令统一用它们:
12
+
13
+ ```powershell
14
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
15
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
16
+ ```
17
+
18
+ > 路径里的用户名按实际情况替换;如果以后装了全局 Node,也可以直接用 `node` / `npm`。
19
+
20
+ ---
21
+
22
+ ## 1. 项目结构
23
+
24
+ ```text
25
+ .
26
+ ├─ package.json # 包清单:dsh.bundle.patch + dsh.client + exports/files
27
+ ├─ cordis.patch.yml # 往 Loader 插入插件行(id: greeting-bubble)
28
+ ├─ index.js # Host 半(空 apply)
29
+ ├─ client.js # 浏览器半:气泡、拖动、余额、slot 注册
30
+ ├─ icon.svg # 插件图标
31
+ ├─ locale/{zh,en}.json # 插件页标题/描述
32
+ ├─ docs/ # 详情页文档 + 本文档
33
+ ├─ test/smoke.mjs # 离线冒烟测试
34
+ └─ README.md / LICENSE / UPLOAD.md
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 2. 本地开发
40
+
41
+ ### 2.1 安装到 DSH(link 方式)
42
+
43
+ 插件页 → **添加插件** → 填入仓库的**绝对路径**(例如 `D:\插件实现`)→ 安装。
44
+
45
+ 也可以用 agent:
46
+
47
+ ```text
48
+ 安装 D:\插件实现 这个插件
49
+ ```
50
+
51
+ ### 2.2 修改代码后,按需要选择刷新级别
52
+
53
+ | 改动 | 生效方式 |
54
+ |---|---|
55
+ | 只改 `client.js` / 样式 / 文案 | 插件页**关闭再打开**开关 → 刷新页面 |
56
+ | 改 `package.json`、`cordis.patch.yml`、宿主逻辑 | 卸载后重装 → 刷新页面 |
57
+ | 换过安装路径、升级/降级版本、出现 `ENOENT` | **完全退出 DSH 再打开**(重启 Host 进程) |
58
+
59
+ > 页面刷新(Ctrl+R)只重载浏览器页面,**不会清 Host 进程的模块缓存**。
60
+
61
+ ### 2.3 为什么必须重启:模块缓存与路径
62
+
63
+ DSH 的 Host 进程用 Node 的 ESM 加载插件。模块一旦被解析,结果会按“说明符 → 实际文件路径”缓存在进程里。
64
+
65
+ 如果插件是 `link` 到某个目录、之后又**删除或移动了那个目录**,Host 缓存仍指向旧路径,于是报:
66
+
67
+ ```
68
+ failed to import: ENOENT: no such file or directory, open '...\old-path\index.js'
69
+ ```
70
+
71
+ **规则:**
72
+
73
+ - 开发目录放在固定位置,**不要删、不要临时复制到别处再安装**;
74
+ - 要移动/删除目录,先到插件页**卸载**插件;
75
+ - 不得已换了路径:重启 DSH。
76
+
77
+ 另外,pnpm 替换 `node_modules` 里的链接目录时,Windows 上偶尔会报 `EPERM`(目录被占用)。这时先卸载,再清理残留(见 2.4),然后重装。
78
+
79
+ ### 2.4 清理安装残留
80
+
81
+ ```powershell
82
+ $nm = 'C:\Users\<用户名>\.dsh\profiles\desktop\node_modules'
83
+ Get-ChildItem $nm -Force | Where-Object { $_.Name -like '*greeting-bubble*' } | ForEach-Object {
84
+ if ($_.LinkType -eq 'Junction') { cmd /c rmdir "$($_.FullName)" } # 只删链接,不删目标
85
+ else { Remove-Item -LiteralPath $_.FullName -Recurse -Force }
86
+ }
87
+ ```
88
+
89
+ > 只对名称包含 `greeting-bubble` 的项操作;不要动其他插件。
90
+
91
+ ---
92
+
93
+ ## 3. 测试
94
+
95
+ 提交前至少跑:
96
+
97
+ ```powershell
98
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
99
+
100
+ node --check index.js
101
+ node --check client.js
102
+ node test/smoke.mjs # 必须输出:ok: ...
103
+ ```
104
+
105
+ 冒烟测试用假的 `window / React / Cordis / Remote` 上下文执行 `client.js`,校验模块 id、slot 注册参数、字典、账号 Remote 注入和组件渲染。
106
+
107
+ 检查 npm 会打包哪些文件:
108
+
109
+ ```powershell
110
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
111
+ & $node $pnpm pack --dry-run
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 4. 版本与发布(npm)
117
+
118
+ ### 4.1 版本号
119
+
120
+ 遵循语义化版本:
121
+
122
+ - 修 bug:`1.2.1`
123
+ - 加功能:`1.3.0`
124
+ - 不兼容改动:`2.0.0`
125
+
126
+ npm **不允许重复发布同一个版本号**,每次发布前必须先改 `package.json` 的 `version`。
127
+
128
+ ### 4.2 登录与令牌
129
+
130
+ 发布需要 npm 账号并开启 2FA(安全密钥/生物识别)。发布令牌放在本机:
131
+
132
+ ```
133
+ C:\Users\<用户名>\AppData\Local\pnpm\config\auth.ini
134
+ ```
135
+
136
+ 内容形如:
137
+
138
+ ```
139
+ //registry.npmjs.org/:_authToken=npm_xxxxx
140
+ ```
141
+
142
+ **令牌绝不提交到仓库**。令牌过期(或误删)后重新生成一个即可:
143
+
144
+ - npm → **Access Tokens** → **Generate New Token** → **Granular Access Token**
145
+ - 权限 **Read and write (publish and stage)**、范围 **All packages**、**Bypass 2FA** 打开
146
+
147
+ > 注意:2027 年 1 月起 npm 收紧“免 2FA 令牌”的直接发布,届时需改用带验证码/可信发布(CI)的方式。
148
+
149
+ ### 4.3 发布
150
+
151
+ ```powershell
152
+ cd D:\插件实现
153
+ $node = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe'
154
+ $pnpm = 'C:\Users\81292\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\pnpm\bin\pnpm.mjs'
155
+
156
+ # 先干跑
157
+ & $node $pnpm publish --dry-run --no-git-checks --access public
158
+
159
+ # 正式发布
160
+ & $node $pnpm publish --no-git-checks --access public
161
+
162
+ # 验证(registry 有 1~2 分钟处理延迟)
163
+ & $node $pnpm view dsh-plugin-greeting-bubble version
164
+ ```
165
+
166
+ ### 4.4 两个常见“不是失败”的现象
167
+
168
+ 1. **`0.0.0-stage` 占位版本**:全新包第一次发布时,npm 先放一个占位版本,真版本 1~2 分钟后生效;不是错误,也不用审批。
169
+ 2. **`minimumReleaseAge` 观察期**:pnpm 默认不自动安装刚发布不久的版本。按包名安装会拿到旧版本;想立即用新版:
170
+
171
+ ```
172
+ dsh-plugin-greeting-bubble@1.2.0
173
+ ```
174
+
175
+ 安装时带上版本号,profile 会自动加入 `minimumReleaseAgeExclude` 白名单。
176
+
177
+ ### 4.5 测试版(可选)
178
+
179
+ 频繁试错时,用预发布版本代替 link 安装,避免路径缓存问题:
180
+
181
+ ```powershell
182
+ # package.json 版本改成 1.2.1-beta.0 后
183
+ & $node $pnpm publish --no-git-checks --access public --tag beta
184
+ ```
185
+
186
+ 安装时填 `dsh-plugin-greeting-bubble@1.2.1-beta.0`;测试通过后再发正式版。
187
+
188
+ ---
189
+
190
+ ## 5. Git
191
+
192
+ ### 5.1 提交与推送
193
+
194
+ ```powershell
195
+ cd D:\插件实现
196
+ git add -A
197
+ git commit -m "feat: xxx (v1.3.0)"
198
+ git tag v1.3.0
199
+ git push
200
+ git push origin v1.3.0
201
+ ```
202
+
203
+ 远端:`https://github.com/liwei169/dsh-plugin-greeting-bubble.git`
204
+
205
+ 推送会使用 Git Credential Manager 已保存的 GitHub 登录;也可以用 PAT(classic,`repo` 权限)作为密码。
206
+
207
+ ### 5.2 GitHub 网络问题
208
+
209
+ 本机到 `github.com` 的 DNS 偶尔会被解析到不可用 IP,表现为推送/安装超时。临时办法(机器级、可撤销):
210
+
211
+ - 管理员编辑 `C:\Windows\System32\drivers\etc\hosts`,加一行
212
+
213
+ ```
214
+ 20.205.243.166 github.com
215
+ ```
216
+
217
+ - 执行 `ipconfig /flushdns`;
218
+ - 用完后删除该行即可。
219
+
220
+ 长期方案:使用稳定的 DNS 或代理。
221
+
222
+ ### 5.3 `.git` 管理文件丢失的应急恢复
223
+
224
+ 如果 `git status` 报 `not a git repository`,但 `.git/objects`、`.git/refs` 还在:
225
+
226
+ ```powershell
227
+ # 1) 重建 .git/HEAD,内容为:ref: refs/heads/main
228
+ # 2) 重建 .git/config,至少包含 core、remote.origin、branch.main
229
+ # 3) 从 refs 重建索引
230
+ git reset --mixed HEAD
231
+ git status -sb
232
+ ```
233
+
234
+ 历史不会丢;`git fsck` 可校验。
235
+
236
+ ---
237
+
238
+ ## 6. 发版 Checklist
239
+
240
+ - [ ] 改代码,`package.json` 版本号 +1
241
+ - [ ] `node --check index.js` / `node --check client.js` 通过
242
+ - [ ] `node test/smoke.mjs` 输出 `ok: ...`
243
+ - [ ] `pnpm pack --dry-run` 文件清单正确(12 个文件左右)
244
+ - [ ] `git add/commit/tag/push`(含 tag)
245
+ - [ ] `pnpm publish --no-git-checks --access public`
246
+ - [ ] `pnpm view dsh-plugin-greeting-bubble version` 确认新版本
247
+ - [ ] 插件页卸载旧版 → 安装 `dsh-plugin-greeting-bubble@新版本` → 重启 DSH
248
+ - [ ] 刷新页面,确认气泡、拖动、余额正常
249
+
250
+ ---
251
+
252
+ ## 7. 常见问题
253
+
254
+ | 现象 | 原因 / 解决 |
255
+ |---|---|
256
+ | 安装报 `EPERM ... rename` | `node_modules` 里有旧目录/链接残留:卸载后按 2.4 清理再装 |
257
+ | 加载报 `ENOENT ... old-path\index.js` | Host 缓存了已删除的安装路径:完全重启 DSH |
258
+ | 插件页显示“未运行”但文件都在 | 同上,多为路径缓存或导入失败,重启后仍失败就看安装日志 |
259
+ | 新版本装不上、装到旧版 | `minimumReleaseAge` 观察期:填 `包名@版本号` 安装 |
260
+ | 气泡没出现 | 插件页确认已启用;刷新;检查控制台 `slot entry crashed`;确认 DSH 版本含 `shell.overlay` |
261
+ | 余额显示 `--` | 未登录 DeepSeek 账号或账号服务不可用;确认设置里账号正常 |
262
+ | `pnpm publish` 报 403 需要 2FA | 令牌没有 Bypass 2FA:重新生成 Granular Token 并打开 Bypass 2FA |
263
+ | `pnpm publish` 报 401 | 令牌过期/被删:重新生成并写入 `auth.ini` |
264
+ | 推送/安装 GitHub 超时 | DNS 问题,见 5.2 |
package/locale/en.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "Greeting bubble",
4
- "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.",
5
4
  "detail": "docs/DETAIL.md"
6
5
  }
7
6
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "右下角问候气泡",
4
- "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡,并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次,点击余额行可立即刷新。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「余额 --」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
3
+ "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡,并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次。余额低于 3 元会显示提醒;点击余额行可展开详情:账户信息、充值/赠送明细、更新时间、插件版本,以及「用量」「充值」快捷入口。支持隐藏金额(隐私模式),按住气泡可拖动并记住位置。点 × 关闭,下次页面加载会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「--」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
5
4
  "detail": "docs/DETAIL.zh.md"
6
5
  }
7
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.2.0",
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": {