dsh-plugin-greeting-bubble 1.5.1 → 1.5.3

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.
Files changed (3) hide show
  1. package/README.md +3 -2
  2. package/client.js +39 -35
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -40,9 +40,10 @@
40
40
  - 今日消费金额只显示金额(`≈ ¥x.xx`);口径是基准余额 − 当前余额,优先用**昨天最后一次读到的余额**(≈ 0 点余额),没有昨天数据则用**今天第一次读到的余额**;充值会使基准同步抬高,不计入消费。
41
41
  - **安装插件之前、或 DSH 未运行期间**的消费无法统计,所以这是“自基准时间起”的估算,不是平台账单。
42
42
  - 详情里可以**隐藏金额(隐私模式)**:金额变为 `••••` 并记住,适合截图/录屏。
43
+ - 金额显示按平台口径**截断到分**(4.618 显示 4.61),与官方页面一致,不做四舍五入。
43
44
  - 未登录、账号服务不可用或请求失败时显示 `--`,不影响其他功能。
44
45
  - 展开后用右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
45
- - **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
46
+ - **按住机器人或卡片可以拖动**:光标变成抓手,拖到任意位置松手即可;位置按“距右下角的偏移”记录,所以窗口缩放、最大化后会继续贴着右下角,不会跑到屏幕外。
46
47
  - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。控件需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
47
48
  - 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
48
49
  - 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
@@ -106,7 +107,7 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
106
107
  | 详情里的「隐藏金额 / 显示金额」 | 切换隐私模式并记住 |
107
108
  | 余额低于 ¥8 | 机器人变橙,胶囊显示橙色圆点 |
108
109
  | 连接断开 | 机器人变灰、闭眼 |
109
- | 刷新页面 | 挂件再次出现,位置保持上次拖到的位置 |
110
+ | 刷新页面 | 挂件再次出现,保持上次拖动的右下角偏移 |
110
111
  | 插件页关闭该包的开关 | 挂件立即消失(HMR 生效时无需刷新) |
111
112
  | 插件页卸载该包 | 彻底移除,不再出现 |
112
113
 
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 viewport px. */
31
- const POSITION_KEY = 'dsh-greeting-bubble:position:v2';
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';
@@ -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?.x === 'number' && typeof value?.y === 'number') {
60
- return { x: value.x, y: value.y };
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.
@@ -104,15 +104,23 @@ window.__ModuleLoader__.load({
104
104
  return currency + ' ';
105
105
  }
106
106
 
107
- /** Display a Platform decimal string with two fraction digits. */
108
- const AMOUNT_FORMAT = new Intl.NumberFormat(undefined, {
109
- minimumFractionDigits: 2,
110
- maximumFractionDigits: 2,
111
- });
107
+ /** Whole-yuan grouping for truncated amounts. */
108
+ const WHOLE_FORMAT = new Intl.NumberFormat(undefined, { maximumFractionDigits: 0 });
112
109
 
110
+ /**
111
+ * Display a Platform amount the way the Platform does: truncate to two
112
+ * fraction digits instead of rounding, so 4.618 shows 4.61 (not 4.62).
113
+ */
113
114
  function formatAmount(value) {
114
115
  const amount = Number(value);
115
- return Number.isFinite(amount) ? AMOUNT_FORMAT.format(amount) : value;
116
+ if (!Number.isFinite(amount)) return value;
117
+ // Round away binary noise at the 1e-9 scale, then truncate to cents.
118
+ const cents = Math.trunc(Math.round(amount * 1e9) / 1e7);
119
+ const sign = cents < 0 ? '-' : '';
120
+ const abs = Math.abs(cents);
121
+ const whole = WHOLE_FORMAT.format(Math.floor(abs / 100));
122
+ const fraction = String(abs % 100).padStart(2, '0');
123
+ return sign + whole + '.' + fraction;
116
124
  }
117
125
 
118
126
  /** Format a wallet list, e.g. "¥11.77 / $1.00"; null when empty. */
@@ -510,7 +518,6 @@ window.__ModuleLoader__.load({
510
518
  const [refreshing, setRefreshing] = React.useState(false);
511
519
  const widgetRef = React.useRef(null);
512
520
  const dragRef = React.useRef(null);
513
- const bottomAnchorRef = React.useRef(null);
514
521
  const suppressClickRef = React.useRef(false);
515
522
  const inFlightRef = React.useRef(null);
516
523
  const profileRef = React.useRef(null);
@@ -604,35 +611,34 @@ window.__ModuleLoader__.load({
604
611
  // eslint-disable-next-line react-hooks/exhaustive-deps
605
612
  }, []);
606
613
 
607
- // Keep a remembered spot on screen when the window shrinks.
614
+ // Keep the remembered offsets valid when the window shrinks.
608
615
  React.useEffect(() => {
609
616
  function handleResize() {
610
617
  setPosition((current) => {
611
618
  const element = widgetRef.current;
612
619
  if (current === null || element === null) return current;
613
- const x = clamp(current.x, 0, window.innerWidth - element.offsetWidth);
614
- const y = clamp(current.y, 0, window.innerHeight - element.offsetHeight);
615
- return x === current.x && y === current.y ? current : { x, y };
620
+ const right = clamp(current.right, 0, Math.max(0, window.innerWidth - element.offsetWidth));
621
+ const bottom = clamp(current.bottom, 0, Math.max(0, window.innerHeight - element.offsetHeight));
622
+ return right === current.right && bottom === current.bottom ? current : { right, bottom };
616
623
  });
617
624
  }
618
625
  window.addEventListener('resize', handleResize);
619
626
  return () => { window.removeEventListener('resize', handleResize); };
620
627
  }, []);
621
628
 
622
- // Keep the widget's bottom edge fixed while expanding: a widget anchored
623
- // near the bottom edge then grows upward instead of running off-screen.
629
+ // Bottom-anchored: expansion grows upward. Only nudge down when the card
630
+ // is taller than the room above it.
624
631
  React.useEffect(() => {
632
+ if (!expanded) return;
625
633
  const element = widgetRef.current;
626
- const bottom = bottomAnchorRef.current;
627
- if (!element || bottom === null) return;
628
- bottomAnchorRef.current = null;
634
+ if (!element) return;
629
635
  const rect = element.getBoundingClientRect();
630
636
  const margin = 8;
631
- const maxTop = Math.max(margin, window.innerHeight - rect.height - margin);
632
- const top = Math.round(clamp(bottom - rect.height, margin, maxTop));
633
- const left = Math.round(clamp(rect.left, margin, Math.max(margin, window.innerWidth - rect.width - margin)));
634
- if (Math.abs(top - rect.top) > 0.5 || Math.abs(left - rect.left) > 0.5) {
635
- setPosition({ x: left, y: top });
637
+ if (rect.top < margin) {
638
+ setPosition((current) => current === null ? current : {
639
+ right: current.right,
640
+ bottom: Math.max(0, window.innerHeight - rect.height - margin),
641
+ });
636
642
  }
637
643
  }, [expanded]);
638
644
 
@@ -670,8 +676,6 @@ window.__ModuleLoader__.load({
670
676
 
671
677
  /** Expand/collapse; the first expansion loads the account profile. */
672
678
  function toggleExpanded() {
673
- const element = widgetRef.current;
674
- if (element) bottomAnchorRef.current = element.getBoundingClientRect().bottom;
675
679
  setExpanded((current) => {
676
680
  const next = !current;
677
681
  if (next && profile === null) {
@@ -703,13 +707,13 @@ window.__ModuleLoader__.load({
703
707
  pointerId: event.pointerId,
704
708
  startX: event.clientX,
705
709
  startY: event.clientY,
706
- left: rect.left,
707
- top: rect.top,
710
+ startRight: window.innerWidth - rect.right,
711
+ startBottom: window.innerHeight - rect.bottom,
708
712
  width: rect.width,
709
713
  height: rect.height,
710
714
  moved: false,
711
715
  };
712
- setPosition({ x: rect.left, y: rect.top });
716
+ setPosition({ right: dragRef.current.startRight, bottom: dragRef.current.startBottom });
713
717
  setDragging(true);
714
718
  if (typeof element.setPointerCapture === 'function') {
715
719
  element.setPointerCapture(event.pointerId);
@@ -725,8 +729,8 @@ window.__ModuleLoader__.load({
725
729
  const dy = event.clientY - drag.startY;
726
730
  if (!drag.moved && Math.abs(dx) + Math.abs(dy) > DRAG_THRESHOLD) drag.moved = true;
727
731
  setPosition({
728
- x: clamp(drag.left + dx, 0, window.innerWidth - drag.width),
729
- y: clamp(drag.top + dy, 0, window.innerHeight - drag.height),
732
+ right: clamp(drag.startRight - dx, 0, Math.max(0, window.innerWidth - drag.width)),
733
+ bottom: clamp(drag.startBottom - dy, 0, Math.max(0, window.innerHeight - drag.height)),
730
734
  });
731
735
  }
732
736
 
@@ -740,8 +744,8 @@ window.__ModuleLoader__.load({
740
744
  if (!element) return;
741
745
  const rect = element.getBoundingClientRect();
742
746
  const dropped = {
743
- x: Math.round(clamp(rect.left, 0, window.innerWidth - rect.width)),
744
- y: Math.round(clamp(rect.top, 0, window.innerHeight - rect.height)),
747
+ right: Math.round(clamp(window.innerWidth - rect.right, 0, Math.max(0, window.innerWidth - rect.width))),
748
+ bottom: Math.round(clamp(window.innerHeight - rect.bottom, 0, Math.max(0, window.innerHeight - rect.height))),
745
749
  };
746
750
  setPosition(dropped);
747
751
  writePosition(dropped);
@@ -777,7 +781,7 @@ window.__ModuleLoader__.load({
777
781
  'data-disconnected': connectionState === 'disconnected' ? '' : undefined,
778
782
  style: position === null
779
783
  ? undefined
780
- : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
784
+ : { right: position.right, bottom: position.bottom, left: 'auto', top: 'auto' },
781
785
  onPointerDown: beginDrag,
782
786
  onPointerMove: moveDrag,
783
787
  onPointerUp: endDrag,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
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": {