dsh-plugin-greeting-bubble 1.1.0 → 1.2.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 +29 -8
- package/client.js +237 -44
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
## 效果
|
|
30
30
|
|
|
31
31
|
- 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
|
|
32
|
+
- **第二行显示账号余额**:`余额 ¥12.34(赠送 ¥3.00)`,来自当前登录的 DeepSeek 账号(充值 + 赠送钱包);每 60 秒刷新一次,**点余额这一行可立即刷新**。
|
|
33
|
+
- 未登录、账号服务不可用或请求失败时显示 `余额 --`,不影响气泡的其他功能。
|
|
32
34
|
- 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
|
|
33
35
|
- **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
|
|
34
36
|
- 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
|
|
@@ -85,8 +87,9 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
|
|
|
85
87
|
|
|
86
88
|
| 操作 | 结果 |
|
|
87
89
|
| --- | --- |
|
|
88
|
-
| 页面加载 |
|
|
90
|
+
| 页面加载 | 气泡出现(每个页面视图一次),并读取一次余额 |
|
|
89
91
|
| **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
|
|
92
|
+
| **点余额那一行** | 立即刷新余额(不用等 60 秒) |
|
|
90
93
|
| 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
|
|
91
94
|
| 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
|
|
92
95
|
| 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
|
|
@@ -132,7 +135,21 @@ localStorage.removeItem('dsh-greeting-bubble:position:v1')
|
|
|
132
135
|
- 底/字色:`--dsw-alias-bg-layer-3`、`--dsw-alias-label-primary`,自动跟随亮/暗主题;
|
|
133
136
|
- 尺寸与字号:`.dsh-greeting-bubble` 的 `font-size`、`gap`、`padding`。
|
|
134
137
|
|
|
135
|
-
### 4.
|
|
138
|
+
### 4. 改余额刷新频率
|
|
139
|
+
|
|
140
|
+
`client.js` 顶部:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const BALANCE_REFRESH_MS = 60_000; // 正常刷新间隔
|
|
144
|
+
const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- 只在页面可见时刷新,切到后台暂停;
|
|
148
|
+
- 失败会退避(60s → 120s → 240s → 300s),成功后恢复 60s;
|
|
149
|
+
- 点击余额那一行会立即刷新并重置退避;
|
|
150
|
+
- 不建议改到 30 秒以下:余额接口是账号接口,不适合高频轮询。
|
|
151
|
+
|
|
152
|
+
### 5. 改成“只问候一次”(可选)
|
|
136
153
|
|
|
137
154
|
默认每次页面加载都会出现。如果希望用户关闭后永久不再出现,在组件里加一个 `localStorage` 开关,例如:
|
|
138
155
|
|
|
@@ -153,7 +170,7 @@ function GreetingBubble({ t }) {
|
|
|
153
170
|
|
|
154
171
|
清除 `localStorage` 里这个键即可让问候重新出现。
|
|
155
172
|
|
|
156
|
-
###
|
|
173
|
+
### 6. 改图标、名称、描述
|
|
157
174
|
|
|
158
175
|
- 图标:`icon.svg`(36×36,纯几何、无文字);
|
|
159
176
|
- 插件页显示的名称与说明:`locale/zh.json`、`locale/en.json` 的 `meta.title` / `meta.description`;
|
|
@@ -193,6 +210,7 @@ package.json
|
|
|
193
210
|
7. **样式走主题变量**:气泡用 `--dsw-alias-bg-layer-3`、`--dsw-alias-border-l3`、`--dsw-alias-label-primary`、`--dsw-alias-interactive-bg-hover` 等 token,亮/暗主题自动切换;组件内的 `<style>` 随组件卸载一起移除。
|
|
194
211
|
8. **文案走 locale**:`locale: NS` 让框架把 `t` 注入组件,切换界面语言时文案实时更新,无需重载。
|
|
195
212
|
9. **Host 端为空**:`index.js` 只导出 `export function apply() {}`。插件不注册工具、不发请求、不写会话日志,因此对模型和会话完全透明。
|
|
213
|
+
10. **余额走账号 Remote**:`ctx.remote.account.getBalance(...)` 由 Host 用本地登录凭据请求 Platform,浏览器只拿到脱敏后的钱包金额;账号令牌永远不进浏览器。未登录(返回 null)或请求失败时显示 `--`。
|
|
196
214
|
|
|
197
215
|
## 文件结构
|
|
198
216
|
|
|
@@ -249,17 +267,20 @@ node test/smoke.mjs
|
|
|
249
267
|
- 依赖 `shell.overlay` 槽;更老的 DSH 版本没有该槽时,插件会安静地不显示,不会报错。
|
|
250
268
|
- 每次页面加载都会出现一次,不记忆关闭状态(如需记忆见[自定义](#自定义))。
|
|
251
269
|
- 浮层位于整帧之上:气泡默认在右下角、输入框上方(距右 20px、距底 84px),可以拖到任意位置;拖动后位置记在 localStorage 里(`dsh-greeting-bubble:position:v1`)。气泡本体需要接收拖动事件,所以它所在的那一小块会接住点击,其余区域不受影响。
|
|
252
|
-
-
|
|
253
|
-
-
|
|
270
|
+
- 余额需要当前**已登录 DeepSeek 账号**;未登录、账号插件未启用或请求失败时显示 `余额 --`,不会报错。余额是 Platform 的实时钱包数据(充值 + 赠送),不是本地估算。
|
|
271
|
+
- 余额只显示在气泡里,不发送给任何第三方;但截图/录屏会带出金额,注意场合。
|
|
272
|
+
- 问候语固定为中文,在任何界面语言下都不翻译;只有按钮提示文字跟随语言。
|
|
273
|
+
- 插件自身不直接联网;余额读取经 Host 的账号服务完成。
|
|
254
274
|
|
|
255
275
|
## English
|
|
256
276
|
|
|
257
|
-
A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
|
|
277
|
+
A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads, with the signed-in account balance on a second line. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
|
|
258
278
|
|
|
259
279
|
- Install: **Plugins → Add plugin** → `dsh-plugin-greeting-bubble` (npm), or `https://github.com/liwei169/dsh-plugin-greeting-bubble` (GitHub).
|
|
260
|
-
- It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its
|
|
280
|
+
- It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its labels, and keeps every registration inside `ctx.effect` / `ctx.slots.inject` so disabling the bundle removes the bubble again.
|
|
261
281
|
- Dragging uses pointer capture, clamps to the viewport, and saves the dropped position under `dsh-greeting-bubble:position:v1`.
|
|
262
|
-
-
|
|
282
|
+
- Balance comes from `ctx.remote.account.getBalance(...)` (Host-side Platform call with the stored credential; the browser never sees the account token), refreshed every 60 seconds while the page is visible and on click, with backoff on failure.
|
|
283
|
+
- No direct network access, no data collection, no model-facing behavior.
|
|
263
284
|
|
|
264
285
|
Tested with DeepSeek Harness 0.2.2-rc.5.
|
|
265
286
|
|
package/client.js
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
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
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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.
|
|
18
19
|
*/
|
|
19
20
|
window.__ModuleLoader__.load({
|
|
20
21
|
id: 'dsh-plugin-greeting-bubble',
|
|
@@ -28,6 +29,10 @@ window.__ModuleLoader__.load({
|
|
|
28
29
|
/** Where the reader last dropped the bubble, as viewport px. */
|
|
29
30
|
const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
|
|
30
31
|
|
|
32
|
+
/** Normal refresh cadence while the page is visible, and the failure cap. */
|
|
33
|
+
const BALANCE_REFRESH_MS = 60_000;
|
|
34
|
+
const BALANCE_MAX_BACKOFF_MS = 300_000;
|
|
35
|
+
|
|
31
36
|
/** Read the remembered spot; a corrupt or absent value means "default". */
|
|
32
37
|
function readPosition() {
|
|
33
38
|
try {
|
|
@@ -57,19 +62,51 @@ window.__ModuleLoader__.load({
|
|
|
57
62
|
return Math.max(min, Math.min(value, Math.max(min, max)));
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
/** Platform wallet currency symbol. */
|
|
66
|
+
function currencySymbol(currency) {
|
|
67
|
+
if (currency === 'CNY') return '¥';
|
|
68
|
+
if (currency === 'USD') return '$';
|
|
69
|
+
return currency + ' ';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Display a Platform decimal string with two fraction digits. */
|
|
73
|
+
const AMOUNT_FORMAT = new Intl.NumberFormat(undefined, {
|
|
74
|
+
minimumFractionDigits: 2,
|
|
75
|
+
maximumFractionDigits: 2,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function formatAmount(value) {
|
|
79
|
+
const amount = Number(value);
|
|
80
|
+
return Number.isFinite(amount) ? AMOUNT_FORMAT.format(amount) : value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** True when a wallet amount is exactly zero (Platform sends decimal strings). */
|
|
84
|
+
function isZeroAmount(value) {
|
|
85
|
+
return Number(value) === 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
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) {
|
|
96
|
+
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));
|
|
100
|
+
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(' / ') + ')';
|
|
105
|
+
}
|
|
106
|
+
|
|
60
107
|
/**
|
|
61
108
|
* Component-local stylesheet; unmounting the entry removes it with the
|
|
62
109
|
* node.
|
|
63
|
-
*
|
|
64
|
-
* Placement notes:
|
|
65
|
-
* - The default spot is 84px above the bottom edge, which clears the
|
|
66
|
-
* composer's 34px send button and its card padding.
|
|
67
|
-
* - Once dragged, the card switches to explicit `left`/`top` coordinates
|
|
68
|
-
* and the reader's choice is remembered.
|
|
69
|
-
* - The card now receives pointer events itself (it must, to be dragged);
|
|
70
|
-
* only the layer around it stays click-through.
|
|
71
|
-
* - Radii and elevation reuse the host tokens, so the bubble reads as one
|
|
72
|
-
* of the app's own floating surfaces in both themes.
|
|
73
110
|
*/
|
|
74
111
|
const STYLES = `
|
|
75
112
|
.dsh-greeting-layer {
|
|
@@ -83,10 +120,11 @@ window.__ModuleLoader__.load({
|
|
|
83
120
|
bottom: calc(84px + env(safe-area-inset-bottom, 0px));
|
|
84
121
|
z-index: 1;
|
|
85
122
|
display: flex;
|
|
86
|
-
|
|
87
|
-
|
|
123
|
+
flex-direction: column;
|
|
124
|
+
align-items: stretch;
|
|
125
|
+
gap: 2px;
|
|
88
126
|
box-sizing: border-box;
|
|
89
|
-
max-width: min(
|
|
127
|
+
max-width: min(340px, calc(100vw - 40px));
|
|
90
128
|
padding: 8px 6px 8px 12px;
|
|
91
129
|
border: 0;
|
|
92
130
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l3);
|
|
@@ -105,6 +143,12 @@ window.__ModuleLoader__.load({
|
|
|
105
143
|
.dsh-greeting-bubble[data-dragging] {
|
|
106
144
|
cursor: grabbing;
|
|
107
145
|
}
|
|
146
|
+
.dsh-greeting-main {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 8px;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
}
|
|
108
152
|
.dsh-greeting-wave {
|
|
109
153
|
flex: none;
|
|
110
154
|
font-size: 16px;
|
|
@@ -114,6 +158,31 @@ window.__ModuleLoader__.load({
|
|
|
114
158
|
min-width: 0;
|
|
115
159
|
overflow-wrap: anywhere;
|
|
116
160
|
}
|
|
161
|
+
.dsh-greeting-balance {
|
|
162
|
+
margin: 0;
|
|
163
|
+
padding: 0 0 0 24px;
|
|
164
|
+
border: 0;
|
|
165
|
+
border-radius: var(--dsw-radius-xs, 4px);
|
|
166
|
+
background: transparent;
|
|
167
|
+
color: var(--dsw-alias-label-tertiary);
|
|
168
|
+
font: inherit;
|
|
169
|
+
font-size: 12px;
|
|
170
|
+
line-height: 16px;
|
|
171
|
+
text-align: left;
|
|
172
|
+
width: fit-content;
|
|
173
|
+
max-width: 100%;
|
|
174
|
+
overflow-wrap: anywhere;
|
|
175
|
+
cursor: pointer;
|
|
176
|
+
pointer-events: auto;
|
|
177
|
+
}
|
|
178
|
+
.dsh-greeting-balance:hover {
|
|
179
|
+
color: var(--dsw-alias-label-secondary);
|
|
180
|
+
}
|
|
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;
|
|
185
|
+
}
|
|
117
186
|
.dsh-greeting-close {
|
|
118
187
|
flex: none;
|
|
119
188
|
display: inline-flex;
|
|
@@ -121,6 +190,7 @@ window.__ModuleLoader__.load({
|
|
|
121
190
|
justify-content: center;
|
|
122
191
|
width: 26px;
|
|
123
192
|
height: 26px;
|
|
193
|
+
margin-left: auto;
|
|
124
194
|
padding: 0;
|
|
125
195
|
border: 0;
|
|
126
196
|
border-radius: var(--dsw-radius-sm, 8px);
|
|
@@ -158,15 +228,77 @@ window.__ModuleLoader__.load({
|
|
|
158
228
|
/**
|
|
159
229
|
* The greeting bubble itself.
|
|
160
230
|
*
|
|
161
|
-
* @param props - the framework `t` seat
|
|
231
|
+
* @param props - the framework `t` seat plus the injected balance loader.
|
|
162
232
|
* @returns the bubble, or null once the reader dismissed it.
|
|
163
233
|
*/
|
|
164
|
-
function GreetingBubble({ t }) {
|
|
234
|
+
function GreetingBubble({ t, loadBalance }) {
|
|
165
235
|
const [dismissed, setDismissed] = React.useState(false);
|
|
166
236
|
const [position, setPosition] = React.useState(readPosition);
|
|
167
237
|
const [dragging, setDragging] = React.useState(false);
|
|
238
|
+
const [walletText, setWalletText] = React.useState(null);
|
|
168
239
|
const bubbleRef = React.useRef(null);
|
|
169
240
|
const dragRef = React.useRef(null);
|
|
241
|
+
const inFlightRef = React.useRef(null);
|
|
242
|
+
const timerRef = React.useRef(null);
|
|
243
|
+
const backoffRef = React.useRef(BALANCE_REFRESH_MS);
|
|
244
|
+
const cancelledRef = React.useRef(false);
|
|
245
|
+
|
|
246
|
+
const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback);
|
|
247
|
+
|
|
248
|
+
/** Fetch once, deduplicating concurrent calls; resolves to wallet text or null. */
|
|
249
|
+
function readBalance() {
|
|
250
|
+
if (typeof loadBalance !== 'function') return Promise.resolve(null);
|
|
251
|
+
if (inFlightRef.current !== null) return inFlightRef.current;
|
|
252
|
+
const run = Promise.resolve()
|
|
253
|
+
.then(() => loadBalance())
|
|
254
|
+
.then((result) => {
|
|
255
|
+
if (!result || result.ok !== true) return null;
|
|
256
|
+
return formatBalance(result.value, label('bonus', '赠送'));
|
|
257
|
+
})
|
|
258
|
+
.catch(() => null)
|
|
259
|
+
.finally(() => { inFlightRef.current = null; });
|
|
260
|
+
inFlightRef.current = run;
|
|
261
|
+
return run;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** One polling cycle: refresh, then schedule the next attempt with backoff. */
|
|
265
|
+
function tick() {
|
|
266
|
+
if (cancelledRef.current) return;
|
|
267
|
+
const visible = typeof document === 'undefined' || document.visibilityState !== 'hidden';
|
|
268
|
+
if (!visible) {
|
|
269
|
+
timerRef.current = window.setTimeout(tick, BALANCE_REFRESH_MS);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
void readBalance().then((text) => {
|
|
273
|
+
if (cancelledRef.current) return;
|
|
274
|
+
setWalletText(text);
|
|
275
|
+
backoffRef.current = text === null
|
|
276
|
+
? Math.min(backoffRef.current * 2, BALANCE_MAX_BACKOFF_MS)
|
|
277
|
+
: BALANCE_REFRESH_MS;
|
|
278
|
+
timerRef.current = window.setTimeout(tick, backoffRef.current);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Balance polling: visible-only, deduplicated, backed off on failure.
|
|
283
|
+
React.useEffect(() => {
|
|
284
|
+
cancelledRef.current = false;
|
|
285
|
+
tick();
|
|
286
|
+
function handleVisibility() {
|
|
287
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
|
|
288
|
+
backoffRef.current = BALANCE_REFRESH_MS;
|
|
289
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
290
|
+
tick();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
document.addEventListener('visibilitychange', handleVisibility);
|
|
294
|
+
return () => {
|
|
295
|
+
cancelledRef.current = true;
|
|
296
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
297
|
+
document.removeEventListener('visibilitychange', handleVisibility);
|
|
298
|
+
};
|
|
299
|
+
// The loader is stable for the registration's lifetime.
|
|
300
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
301
|
+
}, []);
|
|
170
302
|
|
|
171
303
|
// Keep a remembered spot on screen when the window shrinks.
|
|
172
304
|
React.useEffect(() => {
|
|
@@ -184,8 +316,18 @@ window.__ModuleLoader__.load({
|
|
|
184
316
|
}, []);
|
|
185
317
|
|
|
186
318
|
if (dismissed) return null;
|
|
187
|
-
const text =
|
|
188
|
-
const dismissLabel =
|
|
319
|
+
const text = label('greeting', '你好,腾盛');
|
|
320
|
+
const dismissLabel = label('dismiss', '关闭问候气泡');
|
|
321
|
+
const balanceLine = label('balance', '余额') + ' ' + (walletText ?? label('unavailable', '--'));
|
|
322
|
+
|
|
323
|
+
/** Manual refresh: reset the backoff and read once. */
|
|
324
|
+
function handleBalanceClick(event) {
|
|
325
|
+
event.stopPropagation();
|
|
326
|
+
backoffRef.current = BALANCE_REFRESH_MS;
|
|
327
|
+
void readBalance().then((value) => {
|
|
328
|
+
if (!cancelledRef.current) setWalletText(value);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
189
331
|
|
|
190
332
|
/** Start a drag: switch to absolute coordinates and capture the pointer. */
|
|
191
333
|
function handlePointerDown(event) {
|
|
@@ -259,38 +401,53 @@ window.__ModuleLoader__.load({
|
|
|
259
401
|
onPointerUp: handlePointerUp,
|
|
260
402
|
onPointerCancel: handlePointerUp,
|
|
261
403
|
},
|
|
262
|
-
h(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
404
|
+
h(
|
|
405
|
+
'div',
|
|
406
|
+
{ className: 'dsh-greeting-main', key: 'main' },
|
|
407
|
+
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),
|
|
412
|
+
h(
|
|
413
|
+
'button',
|
|
414
|
+
{
|
|
415
|
+
className: 'dsh-greeting-close',
|
|
416
|
+
type: 'button',
|
|
417
|
+
title: dismissLabel,
|
|
418
|
+
'aria-label': dismissLabel,
|
|
419
|
+
onClick: () => { setDismissed(true); },
|
|
420
|
+
},
|
|
421
|
+
h(
|
|
422
|
+
'svg',
|
|
423
|
+
{ width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
424
|
+
h('path', {
|
|
425
|
+
d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
|
|
426
|
+
fill: 'none',
|
|
427
|
+
stroke: 'currentColor',
|
|
428
|
+
strokeWidth: 1.4,
|
|
429
|
+
strokeLinecap: 'round',
|
|
430
|
+
}),
|
|
431
|
+
),
|
|
432
|
+
),
|
|
433
|
+
),
|
|
267
434
|
h(
|
|
268
435
|
'button',
|
|
269
436
|
{
|
|
270
|
-
|
|
437
|
+
key: 'balance',
|
|
438
|
+
className: 'dsh-greeting-balance',
|
|
271
439
|
type: 'button',
|
|
272
|
-
title:
|
|
273
|
-
|
|
274
|
-
onClick: () => { setDismissed(true); },
|
|
440
|
+
title: label('refreshBalance', '刷新余额'),
|
|
441
|
+
onClick: handleBalanceClick,
|
|
275
442
|
},
|
|
276
|
-
|
|
277
|
-
'svg',
|
|
278
|
-
{ width: 13, height: 13, viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
279
|
-
h('path', {
|
|
280
|
-
d: 'M2.5 2.5l7 7M9.5 2.5l-7 7',
|
|
281
|
-
fill: 'none',
|
|
282
|
-
stroke: 'currentColor',
|
|
283
|
-
strokeWidth: 1.4,
|
|
284
|
-
strokeLinecap: 'round',
|
|
285
|
-
}),
|
|
286
|
-
),
|
|
443
|
+
balanceLine,
|
|
287
444
|
),
|
|
288
445
|
),
|
|
289
446
|
);
|
|
290
447
|
}
|
|
291
448
|
|
|
292
449
|
return {
|
|
293
|
-
inject: ['slots', 'locale'],
|
|
450
|
+
inject: ['slots', 'locale', 'remote', 'remote.account'],
|
|
294
451
|
/**
|
|
295
452
|
* Register the plugin's dictionary and its single overlay entry.
|
|
296
453
|
* @param ctx - client plugin context.
|
|
@@ -299,17 +456,53 @@ window.__ModuleLoader__.load({
|
|
|
299
456
|
ctx.effect(
|
|
300
457
|
() => ctx.locale.register(NS, {
|
|
301
458
|
// The greeting is the plugin's fixed signature phrase, so it stays
|
|
302
|
-
// identical in every locale; only
|
|
303
|
-
zh: {
|
|
304
|
-
|
|
459
|
+
// identical in every locale; only control labels are localized.
|
|
460
|
+
zh: {
|
|
461
|
+
greeting: '你好,腾盛',
|
|
462
|
+
dismiss: '关闭问候气泡',
|
|
463
|
+
balance: '余额',
|
|
464
|
+
bonus: '赠送',
|
|
465
|
+
unavailable: '--',
|
|
466
|
+
refreshBalance: '刷新余额',
|
|
467
|
+
},
|
|
468
|
+
en: {
|
|
469
|
+
greeting: '你好,腾盛',
|
|
470
|
+
dismiss: 'Dismiss greeting',
|
|
471
|
+
balance: 'Balance',
|
|
472
|
+
bonus: 'Bonus',
|
|
473
|
+
unavailable: '--',
|
|
474
|
+
refreshBalance: 'Refresh balance',
|
|
475
|
+
},
|
|
305
476
|
}),
|
|
306
477
|
'greeting-bubble: dictionaries',
|
|
307
478
|
);
|
|
479
|
+
/** Current request identity for the Host's Platform calls. */
|
|
480
|
+
const metadata = () => {
|
|
481
|
+
let version = '';
|
|
482
|
+
try {
|
|
483
|
+
version = (typeof process !== 'undefined' && process.env && process.env.DSH_CLIENT_VERSION) || '';
|
|
484
|
+
} catch {
|
|
485
|
+
// `process` is absent in some browser builds; an empty version is fine.
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
version,
|
|
489
|
+
locale: ctx.locale.getSnapshot().active,
|
|
490
|
+
timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
const loadBalance = () => {
|
|
494
|
+
const account = ctx.remote && ctx.remote.account;
|
|
495
|
+
if (!account || typeof account.getBalance !== 'function') {
|
|
496
|
+
throw new Error('account service unavailable');
|
|
497
|
+
}
|
|
498
|
+
return account.getBalance(metadata());
|
|
499
|
+
};
|
|
308
500
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
309
501
|
name: 'shell.overlay',
|
|
310
502
|
id: 'greeting-bubble',
|
|
311
503
|
order: 50,
|
|
312
504
|
locale: NS,
|
|
505
|
+
inject: () => ({ loadBalance }),
|
|
313
506
|
}, GreetingBubble));
|
|
314
507
|
},
|
|
315
508
|
};
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Greeting bubble",
|
|
4
|
-
"description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer,
|
|
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.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "右下角问候气泡",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡,并显示当前 DeepSeek 账号余额(充值 + 赠送),每 60 秒刷新一次,点击余额行可立即刷新。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有按钮提示跟随界面语言。余额通过 DSH 账号服务读取,浏览器不接触账号令牌;未登录或读取失败时显示「余额 --」。插件不联网、不收集数据。在「插件」页停用或移除本插件即可彻底去掉。",
|
|
5
5
|
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|