dsh-chrome-bridge 2.0.2 → 2.1.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.
Files changed (53) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/core/ext.js +44 -15
  4. package/core/hosts.js +3 -4
  5. package/core/receipt.js +228 -31
  6. package/core/session.js +11 -14
  7. package/core/tooldef.js +10 -1
  8. package/core/transport.js +67 -17
  9. package/drag.js +118 -36
  10. package/features/frames.js +5 -2
  11. package/i18n/en.js +37 -7
  12. package/i18n/ru.js +37 -7
  13. package/i18n/zh.js +37 -7
  14. package/nav.js +103 -32
  15. package/package.json +1 -1
  16. package/refs.js +317 -77
  17. package/tools/batch.js +311 -0
  18. package/tools/click.js +37 -11
  19. package/tools/dialog.js +19 -2
  20. package/tools/drag.js +52 -9
  21. package/tools/fill.js +71 -22
  22. package/tools/index.js +3 -1
  23. package/tools/input.js +97 -36
  24. package/tools/nav.js +46 -23
  25. package/tools/read.js +2 -0
  26. package/tools/screenshot.js +10 -1
  27. package/tools/tabs.js +16 -2
  28. package/tools/wait.js +14 -6
  29. package/vendor/cb +3 -2
  30. package/vendor/extension/in-page-cursor.js +49 -11
  31. package/vendor/extension/manifest.json +1 -1
  32. package/vendor/extension/popup.css +1 -0
  33. package/vendor/extension/popup.html +6 -3
  34. package/vendor/extension/popup.js +19 -13
  35. package/vendor/extension/sw/actions.js +573 -0
  36. package/vendor/extension/sw/boot.js +7 -1
  37. package/vendor/extension/sw/cdp.js +219 -33
  38. package/vendor/extension/sw/conditions.js +176 -0
  39. package/vendor/extension/sw/confirm.js +39 -7
  40. package/vendor/extension/sw/cursor.js +534 -49
  41. package/vendor/extension/sw/dispatch.js +43 -8
  42. package/vendor/extension/sw/frames.js +643 -49
  43. package/vendor/extension/sw/imaging.js +35 -17
  44. package/vendor/extension/sw/lifecycle.js +82 -0
  45. package/vendor/extension/sw/ops.js +1028 -148
  46. package/vendor/extension/sw/page-access.js +292 -0
  47. package/vendor/extension/sw/popup-api.js +42 -10
  48. package/vendor/extension/sw/record.js +22 -5
  49. package/vendor/extension/sw/snapshot.js +251 -0
  50. package/vendor/extension/sw/state.js +24 -5
  51. package/vendor/extension/sw/tabui.js +10 -2
  52. package/vendor/in-page-cursor.js +49 -11
  53. package/vendor/skill/SKILL.md +8 -7
@@ -1,4 +1,4 @@
1
- // 页内光标浮层(v5)—— 让用户一眼看出 DSH 在页面里干什么,人一伸手它就让路
1
+ // 页内光标浮层(v6)—— 让用户一眼看出 DSH 在页面里干什么,人一伸手它就让路
2
2
  //
3
3
  // 不是系统光标,是注进页面的一层 DOM。扩展用 Runtime.evaluate 或
4
4
  // chrome.scripting.executeScript({ files: ['in-page-cursor.js'], world: 'MAIN' }) 注入一次,之后调:
@@ -40,7 +40,7 @@
40
40
  // * 系统开了「减少动态效果」就不做动画
41
41
 
42
42
  (() => {
43
- const VERSION = 5;
43
+ const VERSION = 6;
44
44
  const TAG = 'dsh-cursor';
45
45
  const BAR_TAG = 'dsh-handoff';
46
46
  const prev = window.__dshCursor;
@@ -190,9 +190,13 @@
190
190
  let x = keep ? keep.x : null;
191
191
  let y = keep ? keep.y : null;
192
192
  let shown = false;
193
+ let hiding = false;
193
194
  let idleTimer = 0;
194
195
  let dormantTimer = 0;
195
196
  let labelTimer = 0;
197
+ let hideTimer = 0;
198
+ let hideAnim = null;
199
+ let nearTimer = 0;
196
200
  let glide = null;
197
201
  let agentUntil = carry && carry.agentUntil > Date.now() ? carry.agentUntil : 0;
198
202
  let taken = carry && carry.taken ? carry.taken : null; // { at, type }:人最近一次接手
@@ -235,10 +239,23 @@
235
239
  tag.classList.toggle('fy', py > vh() - 56);
236
240
  wheel.classList.toggle('low', py < 34);
237
241
  };
238
- /** 人的鼠标凑到 72px 以内:几乎透明,别挡人看字 */
242
+ /** 人的鼠标凑到 72px 以内:几乎透明,别挡人看字;4 秒过期后自动恢复 */
239
243
  const near = () => {
240
- const on = !!lastUser && x !== null && Date.now() - lastUser.at < 4000 && Math.hypot(lastUser.x - x, lastUser.y - y) < 72;
244
+ clearTimeout(nearTimer);
245
+ nearTimer = 0;
246
+ const left = lastUser ? 4000 - (Date.now() - lastUser.at) : 0;
247
+ const on = left > 0 && x !== null && Math.hypot(lastUser.x - x, lastUser.y - y) < 72;
241
248
  cur.classList.toggle('near', on);
249
+ if (on) nearTimer = setTimeout(() => { nearTimer = 0; cur.classList.remove('near'); }, left + 20);
250
+ };
251
+ const cancelHide = () => {
252
+ hiding = false;
253
+ clearTimeout(hideTimer);
254
+ hideTimer = 0;
255
+ if (hideAnim) {
256
+ try { hideAnim.cancel(); } catch {}
257
+ hideAnim = null;
258
+ }
242
259
  };
243
260
  const wake = () => {
244
261
  cur.classList.remove('idle', 'dormant', 'yield');
@@ -268,6 +285,7 @@
268
285
  };
269
286
 
270
287
  const place = (px, py) => {
288
+ cancelHide();
271
289
  raise();
272
290
  if (glide) { glide.cancel(); glide = null; }
273
291
  x = Math.round(px); y = Math.round(py);
@@ -292,6 +310,7 @@
292
310
 
293
311
  const move = (px, py, opts = {}) => {
294
312
  px = Math.round(px); py = Math.round(py);
313
+ cancelHide();
295
314
  raise();
296
315
  wake();
297
316
  if (x === null) { place(px, py); return 0; }
@@ -304,8 +323,8 @@
304
323
  appear();
305
324
  const dx = px - from.x, dy = py - from.y;
306
325
  const dist = Math.hypot(dx, dy);
307
- if (dist < 2 || reduce()) return 0;
308
- const duration = Math.round(opts.duration != null ? opts.duration : Math.min(620, 240 + dist * 0.42));
326
+ if (dist < 2 || opts.duration === 0 || reduce()) return 0;
327
+ const duration = Math.round(opts.duration != null ? opts.duration : Math.min(260, 110 + dist * 0.18));
309
328
  if (opts.straight) { // 拖拽:匀速直线,跟真实的拖动步子对齐
310
329
  glide = cur.animate([{ transform: at(from.x, from.y) }, { transform: at(px, py) }], { duration, easing: 'linear' });
311
330
  return duration;
@@ -350,6 +369,7 @@
350
369
  };
351
370
 
352
371
  const press = () => {
372
+ if (hiding || !shown) return;
353
373
  wake();
354
374
  if (reduce()) return;
355
375
  arrow.animate([
@@ -375,16 +395,18 @@
375
395
  };
376
396
 
377
397
  const click = (px, py, count = 1) => {
398
+ if (hiding || !shown) return;
378
399
  if (px == null) { px = x; py = y; }
379
400
  press();
380
401
  const n = Math.max(1, Math.min(3, Number(count) || 1));
381
402
  for (let i = 0; i < n; i++) ripple(Math.round(px), Math.round(py), i * 130);
382
403
  };
383
404
 
384
- const down = () => { wake(); cur.classList.add('down'); if (!reduce()) arrow.animate([{ transform: 'scale(1)' }, { transform: 'scale(.88)' }], { duration: 120, fill: 'forwards' }); };
385
- const up = () => { wake(); cur.classList.remove('down'); arrow.getAnimations().forEach((a) => a.cancel()); };
405
+ const down = () => { if (hiding || !shown) return; wake(); cur.classList.add('down'); if (!reduce()) arrow.animate([{ transform: 'scale(1)' }, { transform: 'scale(.88)' }], { duration: 120, fill: 'forwards' }); };
406
+ const up = () => { if (hiding || !shown) return; wake(); cur.classList.remove('down'); arrow.getAnimations().forEach((a) => a.cancel()); };
386
407
 
387
408
  const label = (text, ms = 2600) => {
409
+ if (hiding) return;
388
410
  wake();
389
411
  what.textContent = text == null ? '' : String(text);
390
412
  tag.classList.toggle('open', !!what.textContent);
@@ -394,6 +416,7 @@
394
416
  };
395
417
 
396
418
  const scroll = (dy = 1) => {
419
+ if (hiding || !shown) return;
397
420
  wake();
398
421
  wheelPath.setAttribute('d', dy < 0 ? 'M3 7.5 6 4.5 9 7.5' : 'M3 4.5 6 7.5 9 4.5');
399
422
  if (reduce()) return;
@@ -410,9 +433,22 @@
410
433
  clearTimeout(idleTimer);
411
434
  clearTimeout(dormantTimer);
412
435
  clearTimeout(labelTimer);
413
- if (reduce() || !shown) { host.remove(); return; }
414
- cur.animate([{ opacity: getComputedStyle(cur).opacity }, { opacity: 0 }], { duration: 180, fill: 'forwards' });
415
- setTimeout(() => host.remove(), 200);
436
+ clearTimeout(nearTimer);
437
+ nearTimer = 0;
438
+ cancelHide();
439
+ hiding = true;
440
+ const wasShown = shown;
441
+ shown = false;
442
+ if (reduce() || !wasShown || !host.isConnected) { host.remove(); return; }
443
+ hideAnim = cur.animate([{ opacity: getComputedStyle(cur).opacity }, { opacity: 0 }], { duration: 180, fill: 'forwards' });
444
+ hideTimer = setTimeout(() => {
445
+ hideTimer = 0;
446
+ if (hideAnim) {
447
+ try { hideAnim.cancel(); } catch {}
448
+ hideAnim = null;
449
+ }
450
+ host.remove();
451
+ }, 200);
416
452
  };
417
453
 
418
454
  const pos = () => (x === null ? null : { x, y });
@@ -583,6 +619,8 @@
583
619
  clearTimeout(idleTimer);
584
620
  clearTimeout(dormantTimer);
585
621
  clearTimeout(labelTimer);
622
+ clearTimeout(nearTimer);
623
+ cancelHide();
586
624
  removeBar(false);
587
625
  host.remove();
588
626
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "DSH Bridge",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "description": "__MSG_extDescription__",
6
6
  "default_locale": "en",
7
7
  "minimum_chrome_version": "116",
@@ -298,6 +298,7 @@ code { font: 500 12.5px var(--mono); letter-spacing: -0.2px; }
298
298
 
299
299
  /* ── 系统开关 ── */
300
300
 
301
+ .cursor-pace { font: inherit; color: var(--label); background: var(--fill); border: 0; border-radius: 7px; padding: 5px; }
301
302
  .toggle { cursor: pointer; user-select: none; }
302
303
  .toggle input { position: absolute; opacity: 0; pointer-events: none; }
303
304
  .switch { position: relative; flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--track); transition: background 0.25s ease; }
@@ -60,9 +60,12 @@
60
60
  </label>
61
61
  <label class="row toggle">
62
62
  <span class="tile blue" aria-hidden="true"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M5 3.4v15.4c0 .75.9 1.12 1.42.58l3.6-3.76 2.9 5.94c.24.48.82.68 1.3.45l1.9-.92c.48-.23.68-.8.45-1.28l-2.88-5.9 5.2-.18c.77-.03 1.13-.97.56-1.5L6.64 2.7C6.08 2.18 5 2.6 5 3.4z"/></svg></span>
63
- <span class="row-main"><span class="row-title" data-i18n="cursor">页面里显示 DSH 光标</span><span class="row-hint" data-i18n="cursorHint">只管显示,关掉也照常操作</span></span>
64
- <input type="checkbox" role="switch" data-act="cursor" checked>
65
- <span class="switch" aria-hidden="true"></span>
63
+ <span class="row-main"><span class="row-title" data-i18n="cursor">页面里显示 DSH 光标</span><span class="row-hint" data-i18n="cursorHint">流畅模式会等光标到位再点击</span></span>
64
+ <select data-act="cursor" class="cursor-pace">
65
+ <option value="fast" data-i18n="paceFast">极速</option>
66
+ <option value="smooth" data-i18n="paceSmooth">流畅</option>
67
+ <option value="off" data-i18n="paceOff">关闭</option>
68
+ </select>
66
69
  </label>
67
70
  <label class="row toggle">
68
71
  <span class="tile orange" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"><rect x="1.8" y="4.6" width="9.6" height="8.6" rx="1.6"/><path d="M4.6 4.6V3.4c0-.9.7-1.6 1.6-1.6h6.4c.9 0 1.6.7 1.6 1.6v5.6c0 .9-.7 1.6-1.6 1.6h-1.2"/></svg></span>
@@ -51,7 +51,8 @@ const I18N = {
51
51
  pause: '允许 DSH 控制浏览器',
52
52
  pauseHint: '关掉后,DSH 碰不了浏览器',
53
53
  cursor: '页面里显示 DSH 光标',
54
- cursorHint: '只管显示,关掉也照常操作',
54
+ paceFast: '极速', paceSmooth: '流畅', paceOff: '关闭',
55
+ cursorHint: '流畅模式会等光标到位再点击',
55
56
  window: '新页开在单独窗口',
56
57
  windowHint: '关掉就开在你当前窗口的后台',
57
58
  files: '上传文件',
@@ -171,7 +172,7 @@ const I18N = {
171
172
  tabs: '列标签页', open: '开标签页', close: '关标签页', activate: '切标签页', text: '读文字', html: '读网页源码',
172
173
  attr: '读属性', info: '页面信息', eval: '运行脚本', click: '点击', clickEl: '点击', clickText: '点击',
173
174
  type: '打字', key: '按键', select: '选下拉', upload: '传文件', focus: '聚焦', hover: '悬停', scroll: '滚动',
174
- nav: '跳转', shot: '截图', waitFor: '等元素', dialog: '处理弹窗', console: '看控制台', network: '看网络请求',
175
+ nav: '跳转', historyNav: '后退/前进', shot: '截图', waitFor: '等元素', dialog: '处理弹窗', console: '看控制台', network: '看网络请求',
175
176
  cursor: '光标', attach: '开始控制', detach: '放开', screencast: '录屏', userRelease: '你放开了',
176
177
  'cdp:Input.dispatchMouseEvent': '鼠标', 'cdp:Page.captureScreenshot': '截图', 'cdp:Page.reload': '刷新',
177
178
  'cdp:Page.navigateToHistoryEntry': '后退/前进', 'cdp:Network.getResponseBody': '看返回内容',
@@ -189,7 +190,8 @@ const I18N = {
189
190
  pause: 'Let DSH control the browser',
190
191
  pauseHint: 'Off: DSH can\'t touch the browser',
191
192
  cursor: 'Show the DSH cursor',
192
- cursorHint: 'Off: just hidden; DSH keeps working',
193
+ paceFast: 'Fast', paceSmooth: 'Smooth', paceOff: 'Off',
194
+ cursorHint: 'Smooth waits for the cursor before clicking',
193
195
  window: 'New pages in a separate window',
194
196
  windowHint: 'Off: background tabs in your current window',
195
197
  files: 'File uploads',
@@ -309,7 +311,7 @@ const I18N = {
309
311
  tabs: 'List tabs', open: 'Open tab', close: 'Close tab', activate: 'Switch tab', text: 'Read text', html: 'Read HTML',
310
312
  attr: 'Read attribute', info: 'Page info', eval: 'Run script', click: 'Click', clickEl: 'Click', clickText: 'Click',
311
313
  type: 'Type', key: 'Key press', select: 'Select', upload: 'Upload', focus: 'Focus', hover: 'Hover', scroll: 'Scroll',
312
- nav: 'Navigate', shot: 'Screenshot', waitFor: 'Wait for element', dialog: 'Handle dialog', console: 'Console', network: 'Network',
314
+ nav: 'Navigate', historyNav: 'Back/forward', shot: 'Screenshot', waitFor: 'Wait for element', dialog: 'Handle dialog', console: 'Console', network: 'Network',
313
315
  cursor: 'Cursor', attach: 'Take control', detach: 'Release', screencast: 'Record', userRelease: 'You released it',
314
316
  'cdp:Input.dispatchMouseEvent': 'Mouse', 'cdp:Page.captureScreenshot': 'Screenshot', 'cdp:Page.reload': 'Reload',
315
317
  'cdp:Page.navigateToHistoryEntry': 'Back/forward', 'cdp:Network.getResponseBody': 'Response body',
@@ -327,7 +329,8 @@ const I18N = {
327
329
  pause: 'Разрешить управлять браузером',
328
330
  pauseHint: 'Выкл.: DSH не может трогать браузер',
329
331
  cursor: 'Показывать курсор DSH',
330
- cursorHint: 'Выкл.: курсор скрыт, работа идёт',
332
+ paceFast: 'Быстро', paceSmooth: 'Плавно', paceOff: 'Выкл.',
333
+ cursorHint: 'В плавном режиме щелчок следует за курсором',
331
334
  window: 'Новые страницы в отдельном окне',
332
335
  windowHint: 'Выкл.: фоновые вкладки в текущем окне',
333
336
  files: 'Загрузка файлов',
@@ -447,7 +450,7 @@ const I18N = {
447
450
  tabs: 'Список вкладок', open: 'Открыть вкладку', close: 'Закрыть вкладку', activate: 'Переключить вкладку', text: 'Текст', html: 'HTML',
448
451
  attr: 'Атрибут', info: 'Сведения', eval: 'Скрипт', click: 'Клик', clickEl: 'Клик', clickText: 'Клик',
449
452
  type: 'Ввод', key: 'Клавиша', select: 'Выбор', upload: 'Файл', focus: 'Фокус', hover: 'Наведение', scroll: 'Прокрутка',
450
- nav: 'Переход', shot: 'Скриншот', waitFor: 'Ожидание элемента', dialog: 'Диалог', console: 'Консоль', network: 'Сеть',
453
+ nav: 'Переход', historyNav: 'Назад/вперёд', shot: 'Скриншот', waitFor: 'Ожидание элемента', dialog: 'Диалог', console: 'Консоль', network: 'Сеть',
451
454
  cursor: 'Курсор', attach: 'Начало управления', detach: 'Отпустить', screencast: 'Запись', userRelease: 'Вы отпустили',
452
455
  'cdp:Input.dispatchMouseEvent': 'Мышь', 'cdp:Page.captureScreenshot': 'Скриншот', 'cdp:Page.reload': 'Обновить',
453
456
  'cdp:Page.navigateToHistoryEntry': 'Назад/вперёд', 'cdp:Network.getResponseBody': 'Ответ сервера',
@@ -669,10 +672,9 @@ function renderStatus(st) {
669
672
 
670
673
  function renderSettings(st) {
671
674
  const pause = document.querySelector('input[data-act="pause"]')
672
- const cursor = document.querySelector('input[data-act="cursor"]')
675
+ const cursor = document.querySelector('select[data-act="cursor"]')
673
676
  if (pause.checked !== !st.paused) pause.checked = !st.paused
674
- const showCursor = st.showCursor !== false
675
- if (cursor.checked !== showCursor) cursor.checked = showCursor
677
+ if (!cursor.disabled) cursor.value = st.cursorPace || (st.showCursor === false ? 'off' : 'fast')
676
678
  const win = document.querySelector('input[data-act="window"]')
677
679
  const ownWindow = st.ownWindow !== false
678
680
  if (win.checked !== ownWindow) win.checked = ownWindow
@@ -996,21 +998,25 @@ document.addEventListener('click', async (ev) => {
996
998
  /** 开关的「后台确认过的」状态:从上一次拿到的 state 里读;还没拿到过就当是点之前的样子 */
997
999
  const SWITCHES = {
998
1000
  pause: { confirmed: (st) => !st.paused, msg: (on) => ({ on: !on }), ok: (on) => (on ? T('resumedToast') : T('pausedToast')) },
999
- cursor: { confirmed: (st) => st.showCursor !== false, msg: (on) => ({ on }), ok: (on) => (on ? T('cursorOn') : T('cursorOff')) },
1001
+ cursor: { confirmed: (st) => st.cursorPace || (st.showCursor === false ? 'off' : 'fast'), msg: (cursorPace) => ({ cursorPace }), ok: (pace) => (pace === 'off' ? T('cursorOff') : `${T('cursorOn')} · ${T(pace === 'smooth' ? 'paceSmooth' : 'paceFast')}`) },
1000
1002
  window: { confirmed: (st) => st.ownWindow !== false, msg: (on) => ({ on }), ok: (on) => (on ? T('windowOn') : T('windowOff')) },
1001
1003
  }
1002
1004
 
1003
1005
  document.addEventListener('change', async (ev) => {
1004
- const input = ev.target.closest('input[data-act]')
1006
+ const input = ev.target.closest('input[data-act],select[data-act]')
1005
1007
  if (!input) return
1006
1008
  const act = input.dataset.act
1007
1009
  const sw = SWITCHES[act]
1008
1010
  if (!sw) return
1009
- const on = input.checked
1011
+ const pace = act === 'cursor'
1012
+ const on = pace ? input.value : input.checked
1013
+ input.disabled = true
1010
1014
  const res = await ask(act, sw.msg(on))
1015
+ input.disabled = false
1011
1016
  if (!res || res.error) {
1012
1017
  // 没改成:开关退回后台确认过的状态,不报成功;也不拿这个错误去画「扩展没响应」
1013
- input.checked = last ? sw.confirmed(last) : !on
1018
+ if (pace) input.value = last ? sw.confirmed(last) : 'fast'
1019
+ else input.checked = last ? sw.confirmed(last) : !on
1014
1020
  toast(T('settingFailed', { e: (res && res.error) || '?' }))
1015
1021
  return
1016
1022
  }