dsh-plugin-greeting-bubble 1.5.0 → 1.5.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 +6 -5
- package/client.js +33 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
- 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入**小机器人 + 气泡卡片**:`🤖 早上好,腾盛 · ¥12.34`(问候语按时间变化)。
|
|
32
32
|
- **折叠态**只显示机器人 + 「问候语 · 金额」胶囊;**点击机器人或胶囊**展开详情,再点一次收起。
|
|
33
|
+
- 展开时**底边保持不动、向上生长**;即使挂在右下角,详情也不会溢出屏幕。
|
|
33
34
|
- 机器人的状态会在视觉上体现:
|
|
34
35
|
- 正常:主题蓝,偶尔眨眼;
|
|
35
36
|
- 刷新中:天线闪烁;
|
|
36
|
-
- 余额 <¥
|
|
37
|
+
- 余额 <¥8:变成橙色;
|
|
37
38
|
- 连接断开:变成灰色并“闭眼”。
|
|
38
39
|
- 展开后显示:账户名/联系方式、**连接状态(断开时可一键重连)**、**今日消费金额估算**、充值余额、最近更新时间,以及「用量」「充值」快捷入口。
|
|
39
40
|
- 今日消费金额只显示金额(`≈ ¥x.xx`);口径是基准余额 − 当前余额,优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费。
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
- 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
|
|
42
43
|
- 未登录、账号服务不可用或请求失败时显示 `--`,不影响其他功能。
|
|
43
44
|
- 展开后用右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
|
|
44
|
-
-
|
|
45
|
+
- **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置按“距右下角的偏移”记录,所以窗口缩放、最大化后会继续贴着右下角,不会跑到屏幕外。
|
|
45
46
|
- 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。控件需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
|
|
46
47
|
- 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
|
|
47
48
|
- 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
|
|
@@ -103,9 +104,9 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
|
|
|
103
104
|
| 详情里的「重连」 | 连接断开时出现,点击立即重连 Host |
|
|
104
105
|
| 详情里的「刷新」 | 立即刷新余额(不用等 60 秒) |
|
|
105
106
|
| 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
|
|
106
|
-
| 余额低于 ¥
|
|
107
|
+
| 余额低于 ¥8 | 机器人变橙,胶囊显示橙色圆点 |
|
|
107
108
|
| 连接断开 | 机器人变灰、闭眼 |
|
|
108
|
-
| 刷新页面 |
|
|
109
|
+
| 刷新页面 | 挂件再次出现,保持上次拖动的右下角偏移 |
|
|
109
110
|
| 插件页关闭该包的开关 | 挂件立即消失(HMR 生效时无需刷新) |
|
|
110
111
|
| 插件页卸载该包 | 彻底移除,不再出现 |
|
|
111
112
|
|
|
@@ -168,7 +169,7 @@ const BALANCE_MAX_BACKOFF_MS = 300_000; // 连续失败后的最大退避
|
|
|
168
169
|
`client.js` 顶部:
|
|
169
170
|
|
|
170
171
|
```js
|
|
171
|
-
const LOW_BALANCE_CNY =
|
|
172
|
+
const LOW_BALANCE_CNY = 8; // 低于这个金额显示“余额不足”
|
|
172
173
|
```
|
|
173
174
|
|
|
174
175
|
隐私模式的状态保存在 localStorage 的 `dsh-greeting-bubble:privacy:v1`;想强制恢复“显示金额”,在控制台执行:
|
package/client.js
CHANGED
|
@@ -27,8 +27,8 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
/** Locale namespace owned by this plugin (registered in `apply`). */
|
|
28
28
|
const NS = 'greetingBubble';
|
|
29
29
|
|
|
30
|
-
/** Where the reader last dropped the widget, as
|
|
31
|
-
const POSITION_KEY = 'dsh-greeting-bubble:position:
|
|
30
|
+
/** Where the reader last dropped the widget, as offsets from the bottom-right corner. */
|
|
31
|
+
const POSITION_KEY = 'dsh-greeting-bubble:position:v3';
|
|
32
32
|
|
|
33
33
|
/** Whether amounts are hidden. */
|
|
34
34
|
const PRIVACY_KEY = 'dsh-greeting-bubble:privacy:v1';
|
|
@@ -38,7 +38,7 @@ window.__ModuleLoader__.load({
|
|
|
38
38
|
const BALANCE_MAX_BACKOFF_MS = 300_000;
|
|
39
39
|
|
|
40
40
|
/** Below this CNY amount the widget warns. */
|
|
41
|
-
const LOW_BALANCE_CNY =
|
|
41
|
+
const LOW_BALANCE_CNY = 8;
|
|
42
42
|
|
|
43
43
|
/** Local-day consumption baseline; reset when the date changes. */
|
|
44
44
|
const CONSUMPTION_KEY = 'dsh-greeting-bubble:consumption:v1';
|
|
@@ -56,8 +56,8 @@ window.__ModuleLoader__.load({
|
|
|
56
56
|
const raw = window.localStorage.getItem(POSITION_KEY);
|
|
57
57
|
if (!raw) return null;
|
|
58
58
|
const value = JSON.parse(raw);
|
|
59
|
-
if (typeof value?.
|
|
60
|
-
return {
|
|
59
|
+
if (typeof value?.right === 'number' && typeof value?.bottom === 'number') {
|
|
60
|
+
return { right: value.right, bottom: value.bottom };
|
|
61
61
|
}
|
|
62
62
|
} catch {
|
|
63
63
|
// Private mode, blocked storage, or malformed JSON: fall through.
|
|
@@ -603,21 +603,37 @@ window.__ModuleLoader__.load({
|
|
|
603
603
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
604
604
|
}, []);
|
|
605
605
|
|
|
606
|
-
// Keep
|
|
606
|
+
// Keep the remembered offsets valid when the window shrinks.
|
|
607
607
|
React.useEffect(() => {
|
|
608
608
|
function handleResize() {
|
|
609
609
|
setPosition((current) => {
|
|
610
610
|
const element = widgetRef.current;
|
|
611
611
|
if (current === null || element === null) return current;
|
|
612
|
-
const
|
|
613
|
-
const
|
|
614
|
-
return
|
|
612
|
+
const right = clamp(current.right, 0, Math.max(0, window.innerWidth - element.offsetWidth));
|
|
613
|
+
const bottom = clamp(current.bottom, 0, Math.max(0, window.innerHeight - element.offsetHeight));
|
|
614
|
+
return right === current.right && bottom === current.bottom ? current : { right, bottom };
|
|
615
615
|
});
|
|
616
616
|
}
|
|
617
617
|
window.addEventListener('resize', handleResize);
|
|
618
618
|
return () => { window.removeEventListener('resize', handleResize); };
|
|
619
619
|
}, []);
|
|
620
620
|
|
|
621
|
+
// Bottom-anchored: expansion grows upward. Only nudge down when the card
|
|
622
|
+
// is taller than the room above it.
|
|
623
|
+
React.useEffect(() => {
|
|
624
|
+
if (!expanded) return;
|
|
625
|
+
const element = widgetRef.current;
|
|
626
|
+
if (!element) return;
|
|
627
|
+
const rect = element.getBoundingClientRect();
|
|
628
|
+
const margin = 8;
|
|
629
|
+
if (rect.top < margin) {
|
|
630
|
+
setPosition((current) => current === null ? current : {
|
|
631
|
+
right: current.right,
|
|
632
|
+
bottom: Math.max(0, window.innerHeight - rect.height - margin),
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}, [expanded]);
|
|
636
|
+
|
|
621
637
|
if (dismissed) return null;
|
|
622
638
|
const greeting = label(greetingKeyForHour(new Date().getHours()), '你好,腾盛');
|
|
623
639
|
const dismissLabel = label('dismiss', '关闭问候气泡');
|
|
@@ -683,13 +699,13 @@ window.__ModuleLoader__.load({
|
|
|
683
699
|
pointerId: event.pointerId,
|
|
684
700
|
startX: event.clientX,
|
|
685
701
|
startY: event.clientY,
|
|
686
|
-
|
|
687
|
-
|
|
702
|
+
startRight: window.innerWidth - rect.right,
|
|
703
|
+
startBottom: window.innerHeight - rect.bottom,
|
|
688
704
|
width: rect.width,
|
|
689
705
|
height: rect.height,
|
|
690
706
|
moved: false,
|
|
691
707
|
};
|
|
692
|
-
setPosition({
|
|
708
|
+
setPosition({ right: dragRef.current.startRight, bottom: dragRef.current.startBottom });
|
|
693
709
|
setDragging(true);
|
|
694
710
|
if (typeof element.setPointerCapture === 'function') {
|
|
695
711
|
element.setPointerCapture(event.pointerId);
|
|
@@ -705,8 +721,8 @@ window.__ModuleLoader__.load({
|
|
|
705
721
|
const dy = event.clientY - drag.startY;
|
|
706
722
|
if (!drag.moved && Math.abs(dx) + Math.abs(dy) > DRAG_THRESHOLD) drag.moved = true;
|
|
707
723
|
setPosition({
|
|
708
|
-
|
|
709
|
-
|
|
724
|
+
right: clamp(drag.startRight - dx, 0, Math.max(0, window.innerWidth - drag.width)),
|
|
725
|
+
bottom: clamp(drag.startBottom - dy, 0, Math.max(0, window.innerHeight - drag.height)),
|
|
710
726
|
});
|
|
711
727
|
}
|
|
712
728
|
|
|
@@ -720,8 +736,8 @@ window.__ModuleLoader__.load({
|
|
|
720
736
|
if (!element) return;
|
|
721
737
|
const rect = element.getBoundingClientRect();
|
|
722
738
|
const dropped = {
|
|
723
|
-
|
|
724
|
-
|
|
739
|
+
right: Math.round(clamp(window.innerWidth - rect.right, 0, Math.max(0, window.innerWidth - rect.width))),
|
|
740
|
+
bottom: Math.round(clamp(window.innerHeight - rect.bottom, 0, Math.max(0, window.innerHeight - rect.height))),
|
|
725
741
|
};
|
|
726
742
|
setPosition(dropped);
|
|
727
743
|
writePosition(dropped);
|
|
@@ -757,7 +773,7 @@ window.__ModuleLoader__.load({
|
|
|
757
773
|
'data-disconnected': connectionState === 'disconnected' ? '' : undefined,
|
|
758
774
|
style: position === null
|
|
759
775
|
? undefined
|
|
760
|
-
: {
|
|
776
|
+
: { right: position.right, bottom: position.bottom, left: 'auto', top: 'auto' },
|
|
761
777
|
onPointerDown: beginDrag,
|
|
762
778
|
onPointerMove: moveDrag,
|
|
763
779
|
onPointerUp: endDrag,
|