dsh-bili-watch 0.2.21 → 0.2.23

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/client.js +29 -6
  2. package/index.js +16 -5
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -420,20 +420,43 @@ window.__ModuleLoader__.load({
420
420
  )
421
421
  }
422
422
 
423
- // 多个插件的顶部横幅都固定在 top:0,会互相盖住;按 DOM 顺序统一往下排。
423
+ // 内核的 shell.overlay 是 position:absolute;inset:0 的一层,子元素各自定位、不会自动堆叠,
424
+ // 所以几个插件的顶部横幅都写 top:0 时会互相盖住,需要有东西统一往下排。
425
+ //
426
+ // 2026-10-25 改(P2-66):原来每 2 秒全量重排一次,既白白占 CPU,也会把别人在两次重排之间
427
+ // 自己调的 top 覆盖掉。现在只在真的变化时排:子节点增删(插件挂载/卸载)+ 容器高度变化。
428
+ // 写 top 前先比较,值相同就不写——否则会触发自己观察到的再次变化,形成回环。
429
+ // 只动 top 一个属性,其余内联样式不碰。
424
430
  function relayoutBanners() {
425
- const els = document.querySelectorAll('[data-pmc-banner],[data-ms-overlay],[data-bl-overlay]');
431
+ const layer = document.querySelector('[data-shell-overlay]');
432
+ if (!layer) return;
426
433
  let top = 0;
427
- for (const el of els) {
434
+ for (const el of layer.children) {
428
435
  const height = el.offsetHeight;
429
436
  if (!height) continue;
430
- el.style.top = top + 'px';
437
+ const want = top + 'px';
438
+ if (el.style.top !== want) el.style.top = want;
431
439
  top += height;
432
440
  }
433
441
  }
434
442
  if (typeof window !== 'undefined' && !window.__dshBannerRelayout) {
435
- window.__dshBannerRelayout = setInterval(relayoutBanners, 2000);
436
- setTimeout(relayoutBanners, 300);
443
+ let scheduled = false;
444
+ const schedule = () => {
445
+ if (scheduled) return;
446
+ scheduled = true;
447
+ requestAnimationFrame(() => { scheduled = false; relayoutBanners(); });
448
+ };
449
+ const layer = document.querySelector('[data-shell-overlay]');
450
+ const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null;
451
+ const watchHeights = () => {
452
+ if (!ro) return;
453
+ for (const el of document.querySelectorAll('[data-pmc-banner],[data-ms-overlay],[data-bl-overlay]')) ro.observe(el);
454
+ };
455
+ if (layer) {
456
+ new MutationObserver(() => { schedule(); watchHeights(); }).observe(layer, { childList: true });
457
+ }
458
+ setTimeout(() => { relayoutBanners(); watchHeights(); }, 300);
459
+ window.__dshBannerRelayout = true;
437
460
  }
438
461
 
439
462
  // 缺依赖横幅(shell.overlay)
package/index.js CHANGED
@@ -357,21 +357,32 @@ function writeDepsCfg(patch) {
357
357
  }
358
358
 
359
359
  /**
360
- * 弹原生选目录框(Windows)。脚本里只用 ASCII,避免 PS 5.1 按 ANSI 解码中文变乱。
360
+ * 弹原生选目录框(Windows)。脚本里只用 ASCII,避免 PS 5.1 按 ANSI 解码中文变乱;
361
+ * 选中的路径经 UTF-8 文件回传,不走 stdout——PS 5.1 的管道输出是当前代码页(中文系统为 GBK),
362
+ * 中文路径经管道会变成问号(2026-10-24 实测:带中文的目录名过管道后,中文段全变成 ?)。
361
363
  * 取消返回 null;非 Windows 直接报错,让面板提示手填。
362
364
  */
363
365
  function pickFolderDialog() {
364
366
  return new Promise((resolve, reject) => {
365
367
  if (process.platform !== 'win32') return reject(new Error('folder picker is Windows only; set the path manually'))
366
- const script = 'Add-Type -AssemblyName System.Windows.Forms; $d = New-Object System.Windows.Forms.FolderBrowserDialog; $d.Description = "bili-watch cache folder"; if ($d.ShowDialog() -eq "OK") { [Console]::Out.Write($d.SelectedPath) }'
368
+ const outFile = join(tmpdir(), `bili-watch-pick-${Date.now()}.txt`)
369
+ const script = [
370
+ 'Add-Type -AssemblyName System.Windows.Forms',
371
+ '$d = New-Object System.Windows.Forms.FolderBrowserDialog',
372
+ '$d.Description = "bili-watch cache folder"',
373
+ 'if ($d.ShowDialog() -eq "OK") { [IO.File]::WriteAllText(\'' + outFile + '\', $d.SelectedPath, (New-Object Text.UTF8Encoding($false))) }',
374
+ ].join('; ')
367
375
  const ps = spawn('powershell.exe', ['-NoProfile', '-STA', '-Command', script], { windowsHide: false })
368
- let out = ''
369
376
  let err = ''
370
- ps.stdout.on('data', (c) => { out += c })
371
377
  ps.stderr.on('data', (c) => { err += c })
372
378
  ps.on('close', (code) => {
379
+ let picked = ''
380
+ try {
381
+ if (existsSync(outFile)) picked = readFileSync(outFile, 'utf8').trim()
382
+ } catch {}
383
+ try { rmSync(outFile, { force: true }) } catch {}
373
384
  if (code !== 0) return reject(new Error(err.trim() || ('powershell exit ' + code)))
374
- resolve(out.trim() || null)
385
+ resolve(picked || null)
375
386
  })
376
387
  ps.on('error', reject)
377
388
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bili-watch",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "private": false,
5
5
  "description": "把 B 站视频读成文本给 DSH agent 用:元数据、评论、弹幕、字幕、本地转写、抽帧 OCR;支持 b23.tv 短链与 av 号,抽帧缓存目录可换。只读命令零依赖。",
6
6
  "type": "module",