@andy.ian/dsh-homing 2.3.5 → 2.3.8
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/lib/mobile-patch.mjs +80 -10
- package/package.json +1 -1
package/lib/mobile-patch.mjs
CHANGED
|
@@ -17,6 +17,15 @@ export const MOBILE_CSS = `html { -webkit-text-size-adjust: 100%; }
|
|
|
17
17
|
@media (max-width: 760px) {
|
|
18
18
|
[class*="_frame"] { min-width: 0; }
|
|
19
19
|
}
|
|
20
|
+
/* 浮层(额度弹窗、菜单、对话框)先按视口限宽/限高:
|
|
21
|
+
宽度超过屏幕的弹窗即使能平移也一定有内容看不见,限宽后第一帧就在屏幕内,
|
|
22
|
+
再配合 JS 的位置修正,避免「先跑到屏幕外再跳回来」。 */
|
|
23
|
+
[role="dialog"], [role="menu"], [role="listbox"], [data-radix-popper-content-wrapper] {
|
|
24
|
+
max-width: calc(100vw - 16px) !important;
|
|
25
|
+
}
|
|
26
|
+
[role="dialog"] {
|
|
27
|
+
max-height: calc(100vh - 32px) !important;
|
|
28
|
+
}
|
|
20
29
|
`;
|
|
21
30
|
|
|
22
31
|
/**
|
|
@@ -136,20 +145,33 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
136
145
|
return matches[matches.length - 1]
|
|
137
146
|
}
|
|
138
147
|
|
|
139
|
-
/** 从点击目标向上找图片文件名;菜单/侧栏里的点击不处理。
|
|
148
|
+
/** 从点击目标向上找图片文件名;菜单/侧栏里的点击不处理。
|
|
149
|
+
* 返回 { name, node }:node 是真正带文件名的那个祖先容器(用于判断点击是不是落在卡片内的操作按钮上)。 */
|
|
140
150
|
const findClickImageName = (target) => {
|
|
141
151
|
let node = target
|
|
142
152
|
for (let depth = 0; depth < 10 && node !== null && node !== undefined; depth += 1) {
|
|
143
153
|
if (typeof node.closest === 'function') {
|
|
144
154
|
for (const selector of CLICK_IGNORE_SELECTORS) {
|
|
145
|
-
if (node.closest(selector) !== null) return ''
|
|
155
|
+
if (node.closest(selector) !== null) return { name: '', node: null }
|
|
146
156
|
}
|
|
147
157
|
}
|
|
148
158
|
const name = pickImageFileName(node.textContent || '')
|
|
149
|
-
if (name !== '') return name
|
|
159
|
+
if (name !== '') return { name, node }
|
|
150
160
|
node = node.parentElement
|
|
151
161
|
}
|
|
152
|
-
return ''
|
|
162
|
+
return { name: '', node: null }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 点击目标与带文件名的容器之间是否夹着按钮类控件(卡片右侧的下拉箭头、更多按钮等)。
|
|
166
|
+
* 这类控件的文字往往只有图标、不含文件名,但祖先卡片文字里有 —— 不能把它们算作"点卡片"。 */
|
|
167
|
+
const CONTROL_SELECTOR = 'button, [role="button"], [aria-haspopup], [aria-expanded], [tabindex], [data-state]'
|
|
168
|
+
const findNestedControl = (target, stopAt) => {
|
|
169
|
+
let node = target
|
|
170
|
+
while (node !== null && node !== undefined && node !== stopAt) {
|
|
171
|
+
if (typeof node.matches === 'function' && node.matches(CONTROL_SELECTOR)) return node
|
|
172
|
+
node = node.parentElement
|
|
173
|
+
}
|
|
174
|
+
return null
|
|
153
175
|
}
|
|
154
176
|
|
|
155
177
|
/** 打开某文件的预览页:先让服务端按文件名/相对路径在工作区里解析。 */
|
|
@@ -166,8 +188,11 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
166
188
|
try {
|
|
167
189
|
const target = event.target
|
|
168
190
|
if (target === null || target === undefined) return
|
|
169
|
-
const
|
|
191
|
+
const found = findClickImageName(target)
|
|
192
|
+
const name = found.name
|
|
170
193
|
if (name === '') return
|
|
194
|
+
// 卡片内的下拉箭头/更多按钮:应该弹出它自己的菜单,不能被我们拐去预览页
|
|
195
|
+
if (findNestedControl(target, found.node) !== null) return
|
|
171
196
|
// 已经是我们自己的文件链接(比如文件页里的图片名),不要二次拦截
|
|
172
197
|
const anchor = typeof target.closest === 'function' ? target.closest('a[href]') : null
|
|
173
198
|
if (anchor !== null && /^\/files\//u.test(String(anchor.getAttribute('href') ?? ''))) return
|
|
@@ -362,6 +387,17 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
362
387
|
return link
|
|
363
388
|
}
|
|
364
389
|
|
|
390
|
+
// 我们是在 MutationObserver 回调里改 DOM 的:如果每次都「删掉再加一遍」,
|
|
391
|
+
// 自己的改动会再次触发观察器 → 80ms 一次无限循环,菜单项肉眼可见地一直闪
|
|
392
|
+
//(2026-11-22 手机录屏实测)。
|
|
393
|
+
// 用标记 + 数量校验做幂等:已增强过就原地跳过,保证不再产生新 mutation。
|
|
394
|
+
const MENU_MARKER = 'data-dsh-homing-menu'
|
|
395
|
+
const menuIsEnhanced = (menu) =>
|
|
396
|
+
menu.getAttribute(MENU_MARKER) === '1'
|
|
397
|
+
&& menu.querySelectorAll('[data-dsh-homing-download]').length === 1
|
|
398
|
+
&& menu.querySelectorAll('[data-dsh-homing-wall]').length === 1
|
|
399
|
+
&& menu.querySelectorAll('[data-dsh-homing-restart]').length === 1
|
|
400
|
+
|
|
365
401
|
const enhanceMenus = () => {
|
|
366
402
|
const done = new Set()
|
|
367
403
|
for (const item of document.querySelectorAll('[role="menuitem"]')) {
|
|
@@ -369,6 +405,7 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
369
405
|
if (menu === null || done.has(menu)) continue
|
|
370
406
|
if (!MENU_HINT.test(menu.textContent || '')) continue
|
|
371
407
|
done.add(menu)
|
|
408
|
+
if (menuIsEnhanced(menu)) continue
|
|
372
409
|
|
|
373
410
|
for (const old of menu.querySelectorAll('[data-dsh-homing-download],[data-dsh-homing-restart],[data-dsh-homing-wall]')) old.remove()
|
|
374
411
|
|
|
@@ -386,6 +423,8 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
386
423
|
menu.appendChild(download)
|
|
387
424
|
menu.appendChild(wall)
|
|
388
425
|
menu.appendChild(restart)
|
|
426
|
+
// 标记必须在本轮 mutation 被观察器处理前写好(同一个任务内完成),下一轮直接跳过
|
|
427
|
+
menu.setAttribute(MENU_MARKER, '1')
|
|
389
428
|
}
|
|
390
429
|
}
|
|
391
430
|
|
|
@@ -397,11 +436,8 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
397
436
|
}
|
|
398
437
|
}
|
|
399
438
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus(); pruneMenuItems(); scheduleClamp() }, 80)
|
|
403
|
-
})
|
|
404
|
-
menuObserver.observe(document.body, { childList: true, subtree: true })
|
|
439
|
+
// 菜单/浮层的 MutationObserver 在「浮层不越界」定义之后统一注册(见下方),
|
|
440
|
+
// 因为新的浮层出现时要在同一个微任务里立刻修正位置。
|
|
405
441
|
|
|
406
442
|
/* ---------- 浮层不越出屏幕 ----------
|
|
407
443
|
* 额度面板、菜单、对话框大多按「相对触发按钮」定位,窄屏上会有一部分落到
|
|
@@ -472,6 +508,40 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
472
508
|
// 调试/测试入口:也可手动触发一次
|
|
473
509
|
if (window.__dshHomingClampPopovers === undefined) window.__dshHomingClampPopovers = clampPopovers
|
|
474
510
|
|
|
511
|
+
/* ---------- DOM 观察器 ----------
|
|
512
|
+
* 两件事:
|
|
513
|
+
* 1) 新浮层出现时,在 MutationObserver 微任务里「同步」修正位置。
|
|
514
|
+
* MutationObserver 回调发生在浏览器绘制之前,所以用户看到的第一帧就是
|
|
515
|
+
* 修正后的位置,不会出现「先在屏幕外冒出来、120ms 后再跳回来」
|
|
516
|
+
* (2026-11-22 录屏里的 OpenCode 额度弹窗就是这个现象)。
|
|
517
|
+
* 2) 会话菜单增强 + prunes(80ms 防抖,避免 DSH 流式输出时频繁扫描)。
|
|
518
|
+
*/
|
|
519
|
+
const OBSERVED_POPOVER_SELECTOR = 'body > div, [role="dialog"], [role="menu"], [role="listbox"], [data-radix-popper-content-wrapper]'
|
|
520
|
+
const isPopoverNode = (node) => {
|
|
521
|
+
if (node === null || node === undefined || typeof node.matches !== 'function') return false
|
|
522
|
+
try {
|
|
523
|
+
if (node.matches(OBSERVED_POPOVER_SELECTOR)) return true
|
|
524
|
+
return typeof node.querySelector === 'function' && node.querySelector(OBSERVED_POPOVER_SELECTOR) !== null
|
|
525
|
+
} catch (error) {
|
|
526
|
+
return false
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const menuObserver = new MutationObserver((records) => {
|
|
531
|
+
let popoverAdded = false
|
|
532
|
+
for (const record of records) {
|
|
533
|
+
const added = record.addedNodes || []
|
|
534
|
+
for (const node of added) {
|
|
535
|
+
if (isPopoverNode(node)) { popoverAdded = true; break }
|
|
536
|
+
}
|
|
537
|
+
if (popoverAdded) break
|
|
538
|
+
}
|
|
539
|
+
if (popoverAdded) clampPopovers()
|
|
540
|
+
if (menuTimer) return
|
|
541
|
+
menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus(); pruneMenuItems(); scheduleClamp() }, 80)
|
|
542
|
+
})
|
|
543
|
+
menuObserver.observe(document.body, { childList: true, subtree: true })
|
|
544
|
+
|
|
475
545
|
/* ---------- ALIVE_BEACON ----------
|
|
476
546
|
* 告诉插件"用户正在操作":重启脚本据此判断能否安全重启。
|
|
477
547
|
* 手机上打字/滑动手势不会修改会话文件,只有这个信标能反映"人在用"。
|