@ggboy123/dsh-paper-reader 1.7.0 → 1.8.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.
package/reader/index.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html lang="zh">
2
+ <html lang="zh" data-dpr-pdf="pending">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -34,6 +34,22 @@
34
34
  .tbtn:hover { background: var(--bg); }
35
35
  .tbtn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
36
36
  .tbtn:disabled { opacity: .45; cursor: default; }
37
+ /* 顶栏收纳:分组分隔线 / 弹性空隙 / 被菜单替代的按钮隐藏(!important 盖过状态机的 style.display)/
38
+ 弹出菜单本体(绝对定位于 #bar) */
39
+ #bar { position: relative; }
40
+ .bar-sep { flex: none; width: 1px; height: 16px; background: var(--border); }
41
+ .bar-spacer { flex: 1 1 auto; }
42
+ .tucked { display: none !important; }
43
+ .bar-menu { position: absolute; z-index: 60; min-width: 208px; padding: 4px;
44
+ display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border);
45
+ border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.22); }
46
+ .bar-menu[hidden] { display: none !important; }
47
+ .bar-menu button { all: unset; cursor: pointer; padding: 6px 10px; border-radius: 6px;
48
+ font-size: 12.5px; color: var(--text); }
49
+ .bar-menu button:hover { background: var(--bg); }
50
+ .bar-menu button.active { color: var(--accent); font-weight: 600; }
51
+ .bar-menu button:disabled { opacity: .45; cursor: default; }
52
+ .bar-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 6px; }
37
53
  /* 统一 SVG 图标:stroke=currentColor,active/disabled 的变色自动继承到图标 */
38
54
  .tbtn svg.ic { width: 16px; height: 16px; flex: none; }
39
55
  .tbtn svg.spin { transform-origin: center; animation: dpr-spin 1s linear infinite; }
@@ -78,7 +94,13 @@
78
94
  #pdf-pages.paged, #pdf-pages-zh.paged { min-height: 100%; justify-content: safe center; gap: 0; }
79
95
 
80
96
  /* ---------- 翻页控件 ---------- */
81
- #pager { display: flex; align-items: center; gap: 4px; flex: none; }
97
+ /* 翻页条:阅读区底部悬浮居中(#main 的 absolute 锚,不随内容滚动);
98
+ 半透明 + 毛玻璃,hover 加实避免长时间挡字;JS 的 display:''/none 契约不变 */
99
+ #pager { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 30;
100
+ display: flex; align-items: center; gap: 4px; flex: none; padding: 3px 6px;
101
+ background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px);
102
+ border: 1px solid var(--border); border-radius: 999px; box-shadow: 0 3px 14px rgba(0,0,0,.16); }
103
+ #pager:hover { background: var(--panel); }
82
104
  /* 数字居中:text-align:right 会让单页码贴右框边、左侧空一块;
83
105
  上 padding 多 1px —— 数字无下伸部,光字心本就偏高,对称内边距看起来反而偏上 */
84
106
  #page-input { width: 3.5em; padding: 4px 6px 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); font: inherit; font-size: 12.5px; line-height: 20px; text-align: center; }
@@ -240,6 +262,16 @@
240
262
  #note-grip-b { position: absolute; left: 0; right: 16px; bottom: 0; height: 6px; cursor: ns-resize; z-index: 2; }
241
263
 
242
264
  /* ---------- 选中即问浮层 ---------- */
265
+ #ask-scope-row { display: flex; align-items: center; gap: 6px; margin: 2px 0 4px; font-size: 12px; color: var(--text-2); }
266
+ #ask-scope-row select { font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--text); max-width: 60%; }
267
+ #ask-scope-hint { opacity: .75; font-size: 11px; }
268
+ #cfg-pop hr { border: none; border-top: 1px solid var(--border); margin: 12px 0 8px; }
269
+ #cfg-theme-hint { font-size: 11.5px; color: var(--text-2); line-height: 1.5; margin-top: 4px; }
270
+ #ask-scope-row { display: flex; align-items: center; gap: 6px; margin: 2px 0 4px; font-size: 12px; color: var(--text-2); }
271
+ #ask-scope-row select { font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--text); max-width: 60%; }
272
+ #ask-scope-hint { opacity: .75; font-size: 11px; }
273
+ #cfg-pop hr { border: none; border-top: 1px solid var(--border); margin: 12px 0 8px; }
274
+ #cfg-theme-hint { font-size: 11.5px; color: var(--text-2); line-height: 1.5; margin-top: 4px; }
243
275
  #ask-pop { position: fixed; z-index: 50; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: 320px; }
244
276
  #ask-quote { font-size: 12px; color: var(--text-2); max-height: 64px; overflow: hidden; margin-bottom: 8px; border-left: 3px solid var(--accent-soft); padding-left: 8px; }
245
277
  #ask-input { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; resize: none; }
@@ -269,11 +301,16 @@
269
301
 
270
302
  /* ---------- 翻译端点设置浮层 ---------- */
271
303
  /* 阅读器在窄 iframe 里,宽度要能收缩 */
272
- #cfg-pop { position: fixed; z-index: 60; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: min(320px, calc(100vw - 32px)); }
273
- #cfg-pop h3 { margin: 0; font-size: 13px; }
304
+ #cfg-pop, #theme-pop { position: fixed; z-index: 60; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: min(320px, calc(100vw - 32px)); }
305
+ #cfg-pop h3, #theme-pop h3 { margin: 0; font-size: 13px; }
274
306
  #cfg-hint { font-size: 12px; color: var(--text-2); margin: 4px 0 2px; }
275
- #cfg-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 2px; }
276
- #cfg-pop input, #cfg-pop select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; background: var(--panel); color: var(--text); }
307
+ #cfg-pop label, #theme-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 2px; }
308
+ /* checkbox 例外:width:100% 会把它拉满整行、文字被挤到右边很远(实测视觉松散的根因) */
309
+ #cfg-pop input[type="checkbox"], #theme-pop input[type="checkbox"] { width: auto; }
310
+ #theme-pop h3 { display: flex; align-items: center; justify-content: space-between; }
311
+ #theme-close { all: unset; cursor: pointer; font-size: 12px; color: var(--text-2); padding: 2px 6px; border-radius: 4px; }
312
+ #theme-close:hover { background: var(--bg); color: var(--text); }
313
+ #cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; background: var(--panel); color: var(--text); }
277
314
  #cfg-model-hint, #cfg-source { font-size: 11.5px; color: var(--text-2); margin-top: 4px; line-height: 1.5; }
278
315
  #cfg-source:empty { display: none; }
279
316
  #cfg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
@@ -282,6 +319,26 @@
282
319
  #cfg-cancel { background: none; border: none; color: var(--text-2); cursor: pointer; }
283
320
 
284
321
  #toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px; display: none; z-index: 99; max-width: 70%; }
322
+ /* ---------- 深色模式(方案 §A2.1;设置项 §A2.3)----------
323
+ ⚠️ 滤镜只挂 `canvas`,**绝不挂 `.page`**:挂 .page 会连 `.eqLayer` 的热区描边与
324
+ `.textLayer ::selection` 一起反转(热区框变怪色、选中高亮从蓝变橙),
325
+ 并可能影响命中判定所在的层叠上下文。挂 canvas 时文本层/热区层/浮层颜色一律不受影响。 */
326
+ html[data-dpr-pdf="dark"] #pdf-pages .page > canvas,
327
+ html[data-dpr-pdf="dark"] #pdf-pages-zh .page > canvas {
328
+ filter: invert(1) hue-rotate(180deg)
329
+ brightness(var(--dpr-dark-b, 0.92)) contrast(var(--dpr-dark-c, 0.95));
330
+ }
331
+ html[data-dpr-pdf="dark"] .page { background: #1b1b1c; box-shadow: none; }
332
+ /* 深色下阅读器自身 UI(pdfDarkChrome):**只覆写我们的自有变量**,绝不碰 --dsw-*(那是 dsh 的) */
333
+ html[data-dpr-pdf="dark"][data-dpr-chrome="on"] {
334
+ color-scheme: dark;
335
+ --bg: #16181d; --panel: #1e2127; --border: #333a45; --text: #e6e8ec; --text-2: #9aa3b2;
336
+ --accent: #4c9aff; --accent-soft: rgba(76,154,255,.18); --hl: rgba(255,196,0,.45);
337
+ }
338
+ /* 首帧防白闪(§A2.5 R15):主题判定完成前藏住页面区。判定是 <head> 里的**同步**读属性,
339
+ 无网络、无 await ⇒ 正常路径下这个状态在首帧前就被覆盖;JS 完全不跑时阅读器本来就是空白。 */
340
+ html[data-dpr-pdf="pending"] #pdf-pages,
341
+ html[data-dpr-pdf="pending"] #pdf-pages-zh { visibility: hidden; }
285
342
  </style>
286
343
  </head>
287
344
  <body>
@@ -291,36 +348,46 @@
291
348
  <!-- 翻译进度条:只在 babeldoc 跑着时出现(宽度=overall,文字=阶段+百分比),
292
349
  窄列下先让位给按钮(flex:0 1 auto + min-width:0),别把控件挤出去 -->
293
350
  <span id="zh-prog" hidden><span class="track"><span class="fill"></span></span><span class="txt"></span></span>
294
- <button id="pdf-path" style="display:none" title="点击复制文件路径"></button>
295
- <button id="zh-toggle" class="tbtn" title="切换中文译文(没有译文时可生成)" style="display:none" data-icon="translate"></button>
296
- <button id="dual-toggle" class="tbtn" title="用 babeldoc 的中英对照 PDF(模式 A)" style="display:none" data-icon="columns">对照</button>
297
- <button id="split-toggle" class="tbtn" title="原文与中文版并排同步滚动(模式 B)" style="display:none" data-icon="split">分屏</button>
298
- <!-- 「同步滚动」开关(模式 B 的全局偏好):分屏控件旁,只在分屏下可见(模式 A/原文/译文都没有两个滚动条)。
299
- 状态换图标(sync / syncOff,与 mode-toggle 的 paged/scroll 同法)+ title 里 zh/en 说明状态;
300
- 与设置面板里的同一项共用 dpr.syncScroll 键、互相同步。 -->
351
+ <!-- 路径不再占顶栏:藏于此(tucked),悬停状态文字可见完整路径、点击状态文字复制(见下方绑定) -->
352
+ <button id="pdf-path" class="tucked" style="display:none" title="点击复制文件路径"></button>
353
+ <span class="bar-sep"></span>
354
+ <!-- 语言视图收纳(17 控件 → 分组):原文/中文/对照/分屏 四态 + 重译 → 「视图」下拉。
355
+ 原按钮 DOM 保留(.tucked 隐藏)——菜单项转发它们的 click,状态机零改动。
356
+ 「同步滚动」仍按原逻辑仅在分屏下出现(见其原注释)。 -->
357
+ <button id="view-menu-btn" class="tbtn" title="语言视图:原文 / 中文 / 对照 / 分屏 / 重新翻译">视图:原文 ▾</button>
358
+ <button id="zh-toggle" class="tbtn tucked" title="切换中文译文(没有译文时可生成)" style="display:none" data-icon="translate"></button>
359
+ <button id="dual-toggle" class="tbtn tucked" title="用 babeldoc 的中英对照 PDF(模式 A)" style="display:none" data-icon="columns">对照</button>
360
+ <button id="split-toggle" class="tbtn tucked" title="原文与中文版并排同步滚动(模式 B)" style="display:none" data-icon="split">分屏</button>
301
361
  <button id="sync-toggle" class="tbtn" title="同步滚动 / Sync scroll:开(两列一起滚,点击关闭)" style="display:none" data-icon="sync"></button>
302
- <button id="zh-regen" class="tbtn" title="重新翻译:删除现有译文,用当前端点重跑(换模型后用)" style="display:none" data-icon="regen"></button>
303
- <button id="dl-btn" class="tbtn" title="下载 PDF" style="display:none" data-icon="download"></button>
304
- <!-- 在文中查找(Ctrl+F):入口紧挨下载,实际输入条是浮层,不占顶栏宽度 -->
305
- <button id="find-open" class="tbtn" title="在文中查找(Ctrl+F)" style="display:none" data-icon="search"></button>
306
- <!-- 笔记:入口紧挨搜索;点开是「笔记窗口」(列全部笔记 / 新建 / 编辑) -->
307
- <button id="note-open" class="tbtn" title="笔记" style="display:none" data-icon="note"></button>
308
- <span class="spacer"></span>
309
- <button id="mode-toggle" class="tbtn" title="切换 滚动/翻页模式" style="display:none" data-icon="paged"></button>
310
- <span id="pager" style="display:none">
311
- <button id="page-prev" class="tbtn" title="上一页" data-icon="prev"></button>
312
- <input id="page-input" type="text" inputmode="numeric" title="页码,回车跳转">
313
- <span id="page-total">/ ?</span>
314
- <button id="page-next" class="tbtn" title="下一页" data-icon="next"></button>
315
- </span>
316
- <button id="cfg-open" class="tbtn" title="翻译端点设置" data-icon="settings"></button>
362
+ <button id="zh-regen" class="tbtn tucked" title="重新翻译:删除现有译文,用当前端点重跑(换模型后用)" style="display:none" data-icon="regen"></button>
363
+ <span class="bar-sep"></span>
317
364
  <button id="zoom-out" class="tbtn" title="缩小" data-icon="minus"></button>
318
365
  <span id="zoom-label">100%</span>
319
366
  <button id="zoom-in" class="tbtn" title="放大" data-icon="plus"></button>
320
367
  <button id="zoom-fit" class="tbtn">适宽</button>
368
+ <button id="mode-toggle" class="tbtn" title="切换 滚动/翻页模式" style="display:none" data-icon="paged"></button>
369
+ <span class="bar-sep"></span>
370
+ <!-- 在文中查找(Ctrl+F):入口紧挨笔记,实际输入条是浮层,不占顶栏宽度 -->
371
+ <button id="find-open" class="tbtn" title="在文中查找(Ctrl+F)" style="display:none" data-icon="search"></button>
372
+ <!-- 笔记:点开是「笔记窗口」(列全部笔记 / 新建 / 编辑) -->
373
+ <button id="note-open" class="tbtn" title="笔记" style="display:none" data-icon="note"></button>
374
+ <button id="dl-btn" class="tbtn" title="下载 PDF" style="display:none" data-icon="download"></button>
375
+ <span class="bar-spacer"></span>
376
+ <button id="scope-chip" class="tbtn" title="提问范围:本篇(点击切换 本篇/所在专题含子专题)">范围:本篇</button>
377
+ <button id="theme-toggle" class="tbtn" title="PDF 深色模式:跟随 dsh 主题(点击切换 关/跟随/强制深色)">A</button>
321
378
  <button id="eq-toggle" class="tbtn" title="公式引用(MinerU LaTeX)" data-icon="sigma">公式</button>
379
+ <button id="cfg-open" class="tbtn" title="翻译端点设置" data-icon="settings"></button>
322
380
  <span id="ver" title="插件版本">__DPR_VERSION__</span>
323
381
  </div>
382
+ <!-- 顶栏收纳的弹出菜单(绝对定位于 #bar):深色/公式/设置经用户反馈回归顶栏,只留「视图」一个下拉 -->
383
+ <div id="view-menu" class="bar-menu" hidden>
384
+ <button data-act="orig">原文</button>
385
+ <button data-act="zh">中文(纯译文)</button>
386
+ <button data-act="dual">对照(双语同页)</button>
387
+ <button data-act="split">分屏(左右两列)</button>
388
+ <hr>
389
+ <button data-act="regen">重新翻译…</button>
390
+ </div>
324
391
 
325
392
  <div id="main">
326
393
  <div id="split-wrap">
@@ -334,6 +401,14 @@
334
401
  <div id="pdf-pages-zh"></div>
335
402
  </div>
336
403
  </div>
404
+ <!-- 翻页条挪到阅读区底部(悬浮居中,不占顶栏):JS 的 $('pager').style.display 契约不变,
405
+ '' 恢复到的 CSS 默认值从 inline 改为悬浮 flex -->
406
+ <span id="pager" style="display:none">
407
+ <button id="page-prev" class="tbtn" title="上一页" data-icon="prev"></button>
408
+ <input id="page-input" type="text" inputmode="numeric" title="页码,回车跳转">
409
+ <span id="page-total">/ ?</span>
410
+ <button id="page-next" class="tbtn" title="下一页" data-icon="next"></button>
411
+ </span>
337
412
  <div id="eq-panel">
338
413
  <h3>公式</h3>
339
414
  <div id="eq-meta"></div>
@@ -391,6 +466,15 @@
391
466
 
392
467
  <div id="ask-pop">
393
468
  <div id="ask-quote"></div>
469
+ <!-- 提问范围(方案 §B3.3 入口 1):默认「本篇」=改造前行为;「所在专题」会带上整棵子专题的目录内容 -->
470
+ <div id="ask-scope-row">
471
+ <span id="ask-scope-label">范围</span>
472
+ <select id="ask-scope" title="提问时只提供该范围内的目录内容">
473
+ <option value="paper">本篇(默认)</option>
474
+ <option value="topic">所在专题(含子专题)</option>
475
+ </select>
476
+ <span id="ask-scope-hint">范围外内容不会提供给模型</span>
477
+ </div>
394
478
  <textarea id="ask-input" rows="2" placeholder="围绕选中内容提问…"></textarea>
395
479
  <div id="ask-actions">
396
480
  <button id="ask-copy" style="display:none">复制 LaTeX</button>
@@ -429,6 +513,30 @@
429
513
  </div>
430
514
  </div>
431
515
 
516
+ <!-- PDF 深色模式(方案 §A2.3 入口 2):与 dsh 设置面板**共用同一个后端配置**(/api/theme/config),
517
+ 两处不各存一份;改动即时生效,无需点保存。独立于设置面板——「A」按钮专属配置。 -->
518
+ <div id="theme-pop">
519
+ <h3>PDF 深色模式 <button id="theme-close" title="关闭" aria-label="关闭">✕</button></h3>
520
+ <label for="cfg-theme-mode">模式</label>
521
+ <select id="cfg-theme-mode">
522
+ <option value="follow">跟随 dsh 主题(默认)</option>
523
+ <option value="off">关闭(PDF 保持原色)</option>
524
+ <option value="light">强制浅色</option>
525
+ <option value="dark">强制深色</option>
526
+ </select>
527
+ <label for="cfg-theme-strength">强度(越往下越柔和)</label>
528
+ <select id="cfg-theme-strength">
529
+ <option value="0">最黑</option>
530
+ <option value="1">近黑(默认)</option>
531
+ <option value="2">柔和</option>
532
+ <option value="3">纸感</option>
533
+ </select>
534
+ <label for="cfg-theme-chrome" style="display:flex;align-items:center;gap:6px">
535
+ <input id="cfg-theme-chrome" type="checkbox"> 阅读器界面也切深色
536
+ </label>
537
+ <div id="cfg-theme-hint">整页反色方案:图片/照片会褪色偏色;导出的 PDF 始终是原文。(悬停查看实测细节)</div>
538
+ </div>
539
+
432
540
  <!-- 笔记悬停提示:鼠标停在被标注文字上显示笔记内容 -->
433
541
  <div id="note-tip"></div>
434
542
 
@@ -436,6 +544,33 @@
436
544
 
437
545
  <script>
438
546
  'use strict';
547
+ /* 深色首帧判定(方案 §A2.2 的四级降级链 + §A2.5「朝亮色回退」)——必须在首帧**之前**同步完成,
548
+ 否则会出现「先白后黑」的白闪(Firefox/pdf.js #18680 同款公开案例)。放在模块脚本最前面:
549
+ 解析期同步执行、早于首帧,且**不新增第二个 <script> 块**(test/reader-script.mjs 的提取约定)。
550
+ ① 宿主 body[data-ds-dark-theme] ② 宿主 html[data-ds-theme-source] ③ 自身 prefers-color-scheme
551
+ ④ 以上全失败 ⇒ **判亮色**(宁可该黑没黑,绝不误黑);任何异常同样朝亮色回退,绝不冒泡。 */
552
+ var __dprDarkMq = null; // 复用的 (prefers-color-scheme: dark) MediaQueryList(只建一个,见下)
553
+ (function firstFrameTheme() {
554
+ var mode = 'light';
555
+ try { if (!__dprDarkMq && window.matchMedia) __dprDarkMq = window.matchMedia('(prefers-color-scheme: dark)'); } catch (e) { /* 无 matchMedia:走降级链下一级 */ }
556
+ try {
557
+ var pref = 'follow';
558
+ try { pref = localStorage.getItem('dpr.pdfTheme') || 'follow'; } catch (e) { pref = 'follow'; }
559
+ if (pref === 'dark') mode = 'dark';
560
+ else if (pref === 'off' || pref === 'light') mode = 'light';
561
+ else {
562
+ var d = null;
563
+ try { d = window.parent && window.parent !== window ? window.parent.document : null; } catch (e) { d = null; }
564
+ var src = null;
565
+ try { src = d && d.documentElement ? d.documentElement.getAttribute('data-ds-theme-source') : null; } catch (e) { src = null; }
566
+ if (d && d.body && d.body.hasAttribute && d.body.hasAttribute('data-ds-dark-theme')) mode = 'dark';
567
+ else if (src === 'dark') mode = 'dark';
568
+ else if (src === 'light') mode = 'light';
569
+ else if (__dprDarkMq && __dprDarkMq.matches) mode = 'dark';
570
+ }
571
+ } catch (e) { mode = 'light'; }
572
+ try { if (document.documentElement && document.documentElement.setAttribute) document.documentElement.setAttribute('data-dpr-pdf', mode); } catch (e) { /* DOM 异常:保持 pending,不影响其余功能 */ }
573
+ })();
439
574
  /* ================= 基础 ================= */
440
575
  const $ = (id) => document.getElementById(id);
441
576
  /* 顶栏图标:统一的 24×24 描边图标集(stroke=currentColor,active/disabled 变色自动跟随按钮)。
@@ -464,7 +599,8 @@ const ICONS = {
464
599
  };
465
600
  const iconHtml = (name) => `<svg class="ic${name === 'spin' ? ' spin' : ''}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`;
466
601
  // 静态按钮按 data-icon 注入一次;动态按钮(翻译/重翻/模式切换)在状态变化时用同一函数换图标
467
- document.querySelectorAll('#bar [data-icon], #find-window [data-icon], #note-window [data-icon]').forEach((b) => b.insertAdjacentHTML('afterbegin', iconHtml(b.dataset.icon)));
602
+ // #pager:翻页条挪到阅读区底部(#main 内)后也要扫到,否则上一页/下一页图标空白
603
+ document.querySelectorAll('#bar [data-icon], #pager [data-icon], #find-window [data-icon], #note-window [data-icon]').forEach((b) => b.insertAdjacentHTML('afterbegin', iconHtml(b.dataset.icon)));
468
604
  const api = (p, opts) => fetch('/paper-reader/api' + p, opts).then(async (r) => {
469
605
  if (!r.ok) {
470
606
  // 服务端错误体有两种:{error}(参数/权限)与 {reason}(zh/generate 的未启动原因,带完整说明)
@@ -485,12 +621,196 @@ function toast(msg, ms = 3200) {
485
621
  }
486
622
  function esc(s) { return s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])); }
487
623
 
624
+ /* ================= 深色模式(方案 §A2)=================
625
+ 路线:canvas 上打 CSS 滤镜 `invert(1) hue-rotate(180deg)` + 亮度/对比档(实测不破坏几何/选区/热区,
626
+ 见 §A2.1 与 .probe/darkmode-subtopic/e-filter-mechanics-probe.mjs)。
627
+ 主题来源(四级降级链,§A2.2):① 宿主 body[data-ds-dark-theme] ② 宿主 html[data-ds-theme-source]
628
+ ③ 自身 prefers-color-scheme ④ 全失败 ⇒ **亮色**(宁可该黑没黑,绝不误黑)。
629
+ 配置是**服务端唯一一份**(/api/theme/config),阅读器只做镜像(localStorage)+ 跨文档同步。 */
630
+ const DARK_STRENGTHS = [[1, 1], [0.92, 0.95], [0.85, 0.9], [0.8, 0.85]];
631
+ const THEME_PREF_KEY = 'dpr.pdfTheme';
632
+ const THEME_MIRROR_KEY = 'dpr.pdfThemeCfg';
633
+ let dprTheme = { mode: 'follow', strength: 1, chrome: true, curve: { brightness: 0.92, contrast: 0.95 } };
634
+
635
+ /** 宿主(dsh)当前的亮暗:读不到一律返回 null(跨源/沙箱/未写入 ⇒ 交下一级降级)。 */
636
+ function hostThemeSource() {
637
+ let d = null;
638
+ try { d = window.parent !== window ? window.parent.document : null; } catch (e) { return null; }
639
+ if (!d) return null;
640
+ try {
641
+ if (d.body && d.body.hasAttribute && d.body.hasAttribute('data-ds-dark-theme')) return 'dark';
642
+ } catch (e) { /* 继续下一级 */ }
643
+ try {
644
+ const src = d.documentElement && d.documentElement.getAttribute('data-ds-theme-source');
645
+ if (src === 'dark' || src === 'light') return src;
646
+ } catch (e) { /* 继续下一级 */ }
647
+ return null;
648
+ }
649
+
650
+ /** 生效的 PDF 亮暗(配置优先,follow 才探测宿主)。 */
651
+ function effectivePdfTheme() {
652
+ const pref = dprTheme.mode;
653
+ if (pref === 'dark') return 'dark';
654
+ if (pref === 'off' || pref === 'light') return 'light';
655
+ const host = hostThemeSource();
656
+ if (host) return host;
657
+ if (__dprDarkMq && __dprDarkMq.matches) return 'dark';
658
+ return 'light';
659
+ }
660
+
661
+ function applyPdfTheme() {
662
+ const mode = effectivePdfTheme();
663
+ try {
664
+ const root = document.documentElement;
665
+ if (root) {
666
+ if (typeof root.setAttribute === 'function') {
667
+ root.setAttribute('data-dpr-pdf', mode);
668
+ root.setAttribute('data-dpr-chrome', dprTheme.chrome ? 'on' : 'off');
669
+ }
670
+ if (root.style && typeof root.style.setProperty === 'function') {
671
+ root.style.setProperty('--dpr-dark-b', String(dprTheme.curve.brightness));
672
+ root.style.setProperty('--dpr-dark-c', String(dprTheme.curve.contrast));
673
+ }
674
+ }
675
+ } catch (e) { /* DOM 不可用(测试桩/极端宿主):只跳过视觉属性写入 */ }
676
+ const btn = $('theme-toggle');
677
+ if (btn) {
678
+ btn.classList.toggle('active', mode === 'dark');
679
+ const src = dprTheme.mode === 'follow' ? `跟随 dsh(当前 ${mode === 'dark' ? '深色' : '浅色'})` : dprTheme.mode === 'off' ? '关闭' : `强制${dprTheme.mode === 'dark' ? '深色' : '浅色'}`;
680
+ btn.title = `PDF 深色模式:${src}(点击切换 关/跟随/强制深色)`;
681
+ }
682
+ }
683
+
684
+ /** 本地镜像:让 <head> 的首帧判定(无网络)拿到上一次的偏好。 */
685
+ function mirrorTheme() {
686
+ try {
687
+ localStorage.setItem(THEME_PREF_KEY, dprTheme.mode);
688
+ localStorage.setItem(THEME_MIRROR_KEY, JSON.stringify({ mode: dprTheme.mode, strength: dprTheme.strength, chrome: dprTheme.chrome, curve: dprTheme.curve }));
689
+ } catch (e) { /* 无痕模式等:镜像失败不影响本次会话 */ }
690
+ }
691
+
692
+ function setThemeLocal(cfg) {
693
+ if (cfg.mode) dprTheme.mode = cfg.mode;
694
+ if (typeof cfg.strength === 'number') dprTheme.strength = cfg.strength;
695
+ if (typeof cfg.chrome === 'boolean') dprTheme.chrome = cfg.chrome;
696
+ if (cfg.curve) dprTheme.curve = { brightness: cfg.curve.brightness, contrast: cfg.curve.contrast };
697
+ else dprTheme.curve = { brightness: DARK_STRENGTHS[dprTheme.strength][0], contrast: DARK_STRENGTHS[dprTheme.strength][1] };
698
+ mirrorTheme();
699
+ applyPdfTheme();
700
+ syncThemeControls();
701
+ }
702
+
703
+ function syncThemeControls() {
704
+ const m = $('cfg-theme-mode'); if (m) m.value = dprTheme.mode;
705
+ const st = $('cfg-theme-strength'); if (st) st.value = String(dprTheme.strength);
706
+ const ch = $('cfg-theme-chrome'); if (ch) ch.checked = dprTheme.chrome;
707
+ // 模式关闭/强制浅色时,深色相关选项没有生效面:禁用置灰,不留「改了却看似生效」的误导
708
+ if (st) st.disabled = dprTheme.mode === 'off' || dprTheme.mode === 'light';
709
+ if (ch) ch.disabled = dprTheme.mode === 'off' || dprTheme.mode === 'light';
710
+ const hint = $('cfg-theme-hint');
711
+ if (hint) hint.title = '深色是整页反色 + 色相回正:图片/照片会明显褪色偏色(实测纯红 [255,0,0] → 浅粉 [229,134,134],不是真负片);下载/导出的 PDF 始终是原文,不受影响。';
712
+ const chip = $('scope-chip'); if (chip) chip.textContent = '范围:' + (askScopeMode() === 'topic' ? '所在专题' : '本篇');
713
+ }
714
+
715
+ /** 写后端(两处 UI 共用同一个配置;失败只 toast,不回滚本地显示——以服务端为准的语义靠下次拉取纠正)。 */
716
+ async function saveTheme(patch) {
717
+ try {
718
+ const r = await api('/theme/config', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(patch) });
719
+ setThemeLocal({ mode: r.pdfTheme, strength: r.pdfDarkStrength, chrome: r.pdfDarkChrome, curve: r.curve });
720
+ } catch (e) { toast('深色设置保存失败:' + e.message, 5000); }
721
+ }
722
+
723
+ async function loadThemeConfig() {
724
+ try {
725
+ const r = await api('/theme/config');
726
+ setThemeLocal({ mode: r.pdfTheme, strength: r.pdfDarkStrength, chrome: r.pdfDarkChrome, curve: r.curve });
727
+ } catch (e) {
728
+ // 服务端不可用:用镜像(没有镜像就按 follow 探测宿主)——降级,不让深色能力整体失灵
729
+ try {
730
+ const mir = JSON.parse(localStorage.getItem(THEME_MIRROR_KEY) || 'null');
731
+ if (mir && mir.mode) setThemeLocal(mir);
732
+ } catch (e2) { applyPdfTheme(); }
733
+ }
734
+ }
735
+
736
+ // 先用镜像+宿主探测立即上色(首帧就有正确属性),配置到货后再校正
737
+ (function initThemeFromMirror() {
738
+ try {
739
+ const mir = JSON.parse(localStorage.getItem(THEME_MIRROR_KEY) || 'null');
740
+ if (mir && mir.mode) { dprTheme = { ...dprTheme, ...mir }; }
741
+ else { const p = localStorage.getItem(THEME_PREF_KEY); if (p) dprTheme.mode = p; }
742
+ } catch (e) { /* 忽略损坏镜像 */ }
743
+ try { applyPdfTheme() } catch (e) { /* 视觉增强失败绝不影响阅读 */ }
744
+ })();
745
+
746
+ // 宿主主题变化(dsh 切主题)→ 立刻重算;同一文档内只需挂一次 MutationObserver
747
+ (function watchHostTheme() {
748
+ let d = null;
749
+ try { d = window.parent !== window ? window.parent.document : null; } catch (e) { d = null; }
750
+ if (!d || typeof MutationObserver !== 'function') return;
751
+ try {
752
+ const ob = new MutationObserver(() => applyPdfTheme());
753
+ ob.observe(d.body || d.documentElement, { attributes: true, attributeFilter: ['data-ds-dark-theme', 'data-ds-theme-source'] });
754
+ if (d.documentElement) ob.observe(d.documentElement, { attributes: true, attributeFilter: ['data-ds-dark-theme', 'data-ds-theme-source'] });
755
+ } catch (e) { /* 拿不到宿主文档:降级链照常工作 */ }
756
+ })();
757
+
758
+ // 跨文档同步:**不在这里另挂 storage 监听**——全脚本只允许一个 `window storage` 监听
759
+ // (结构性红线,见 test/selection-translate.test.mjs G8:多处监听会回声/双写打架)。
760
+ // 主题镜像的 storage 分支合并在那个唯一入口里按 key 分派(见文件后半的 storage 监听)。
761
+ window.addEventListener('message', (e) => {
762
+ const d = e && e.data;
763
+ if (!d || d.type !== 'dpr:theme' || typeof d !== 'object') return;
764
+ setThemeLocal({ mode: d.pdfTheme, strength: d.pdfDarkStrength, chrome: d.pdfDarkChrome, curve: d.curve });
765
+ });
766
+
767
+ // 「A」按钮:深色配置独立小面板(模式/强度/界面深色三项,改了即时生效,点面板外关闭)
768
+ function toggleThemePop() {
769
+ const pop = $('theme-pop');
770
+ if (pop.style.display === 'block') { pop.style.display = 'none'; return; }
771
+ closeCfgPop(); // 与设置面板互斥:同时只开一个
772
+ pop.style.display = 'block';
773
+ const btn = $('theme-toggle');
774
+ const br = btn.getBoundingClientRect();
775
+ // 靠 A 按钮右对齐、按钮下方;越界时贴边
776
+ pop.style.left = Math.max(8, Math.min(br.right - pop.offsetWidth, window.innerWidth - pop.offsetWidth - 8)) + 'px';
777
+ pop.style.top = Math.min(br.bottom + 8, window.innerHeight - pop.offsetHeight - 8) + 'px';
778
+ }
779
+ $('theme-toggle').onclick = (e) => { e.stopPropagation(); toggleThemePop(); };
780
+ $('theme-close').onclick = () => { $('theme-pop').style.display = 'none'; };
781
+ document.addEventListener('click', (e) => {
782
+ if (e.target.closest('#theme-pop') || e.target.closest('#theme-toggle')) return;
783
+ $('theme-pop').style.display = 'none';
784
+ });
785
+
786
+ $('cfg-theme-mode').onchange = () => saveTheme({ pdfTheme: $('cfg-theme-mode').value });
787
+ $('cfg-theme-strength').onchange = () => saveTheme({ pdfDarkStrength: +$('cfg-theme-strength').value, pdfDarkAdvanced: null });
788
+ $('cfg-theme-chrome').onchange = () => saveTheme({ pdfDarkChrome: $('cfg-theme-chrome').checked });
789
+
790
+ /* ================= 提问范围(方案 §B3.3)=================
791
+ 默认 = **当前论文**(改造前行为,零回归);「所在专题」= 该专题及其整棵子树。
792
+ 只给该范围的目录内容由**服务端**装配,客户端只传 scope。 */
793
+ function askScopeKey() { return current ? `dpr.askScope.${current.topic}/${current.name}` : 'dpr.askScope'; }
794
+ function askScopeMode() {
795
+ try { return localStorage.getItem(askScopeKey()) === 'topic' ? 'topic' : 'paper'; } catch (e) { return 'paper'; }
796
+ }
797
+ function setAskScopeMode(mode) {
798
+ try { localStorage.setItem(askScopeKey(), mode); } catch (e) { /* 忽略 */ }
799
+ const sel = $('ask-scope'); if (sel) sel.value = mode;
800
+ syncThemeControls();
801
+ }
802
+ $('scope-chip').onclick = () => setAskScopeMode(askScopeMode() === 'topic' ? 'paper' : 'topic');
803
+ $('ask-scope').onchange = () => setAskScopeMode($('ask-scope').value);
804
+
488
805
  // 路径复制:与「复制 LaTeX」共用同一个 copyText(剪贴板写入只有一处实现,见文件末尾定义)
489
806
  $('pdf-path').onclick = async () => {
490
807
  const p = $('pdf-path').textContent;
491
808
  if (!p) return;
492
- toast((await copyText(p)) ? '路径已复制' : '复制失败,路径见按钮悬停提示');
809
+ toast((await copyText(p)) ? '路径已复制' : '复制失败,路径见状态文字悬停提示');
493
810
  };
811
+ // 路径收进状态文字:点击「name · N 页」即复制(pdf-path 已 tucked,title 带完整路径)
812
+ $('status').style.cursor = 'pointer';
813
+ $('status').onclick = () => $('pdf-path').click();
494
814
 
495
815
  let current = null; // { topic, name }
496
816
  let zhState = { zh: false, dual: false, busy: false };
@@ -531,11 +851,13 @@ async function openPaper(topic, name, opts = {}) {
531
851
  ? `${name} · ${meta.pageCount ?? '?'} 页`
532
852
  : `${name} · 未转录(提问时会自动转录)`;
533
853
  $('status').textContent = statusMeta;
534
- // 文件路径展示(点击复制):独立于 #status,翻译阶段的 phase 覆写不影响它
854
+ // 文件路径:不再占顶栏一行——挂在 #status 的 title(悬停可见)+ 点击 #status 复制;
855
+ // #pdf-path 按钮 tucked 隐藏,textContent 仍作为路径的唯一载体(复制逻辑读它)
535
856
  const pathBtn = $('pdf-path');
536
857
  pathBtn.textContent = meta.pdfPath || '';
537
- pathBtn.title = (meta.pdfPath || '') + '(点击复制)';
538
858
  pathBtn.style.display = meta.pdfPath ? '' : 'none';
859
+ $('status').title = meta.pdfPath ? `${meta.pdfPath}(点击复制)` : '';
860
+ setAskScopeMode(askScopeMode());
539
861
  await refreshZhState();
540
862
  // 恢复该论文上次的视图模式(持久化复用同一个键,取值域扩到 'split';见 §4.3)
541
863
  const saved = localStorage.getItem(variantKey(topic, name));
@@ -1815,6 +2137,7 @@ function updateViewButtons() {
1815
2137
  // 「同步滚动」开关:与三个视图控件同一个状态机(一处决定所有按钮的可见性/文案/态);
1816
2138
  // 仅分屏下可见 —— 模式 A/原文/译文只有一个滚动条,开关无意义
1817
2139
  updateSyncToggle();
2140
+ try { syncViewMenu(); } catch { /* 初始化次序未到(菜单函数在脚本更后方,事件驱动后即正常) */ }
1818
2141
  }
1819
2142
 
1820
2143
  $('zh-toggle').onclick = async () => {
@@ -1975,6 +2298,7 @@ let cfgRetryForce = false; // 待重试的是不是「重翻」(regen 图标
1975
2298
  let cfgRetryTranslate = false; // 待重试的是不是「划词翻译」(点「译」发现没配端点 → 填完自动重试这次翻译)
1976
2299
 
1977
2300
  async function openCfgPop(retryGenerate) {
2301
+ $('theme-pop').style.display = 'none'; // 与深色面板互斥:同时只开一个
1978
2302
  cfgRetryGenerate = Boolean(retryGenerate);
1979
2303
  let cfg;
1980
2304
  try {
@@ -2006,7 +2330,17 @@ async function openCfgPop(retryGenerate) {
2006
2330
  }
2007
2331
  function closeCfgPop() { $('cfg-pop').style.display = 'none'; cfgRetryGenerate = false; cfgRetryForce = false; cfgRetryTranslate = false; }
2008
2332
 
2009
- $('cfg-open').onclick = () => openCfgPop(false);
2333
+ // toggle 语义:面板开着时再点 ⚙ 直接收回(不重新拉配置重开)
2334
+ $('cfg-open').onclick = (e) => {
2335
+ e.stopPropagation();
2336
+ if ($('cfg-pop').style.display === 'block') { closeCfgPop(); return; }
2337
+ void openCfgPop(false);
2338
+ };
2339
+ document.addEventListener('click', (e) => {
2340
+ if (e.target.closest('#cfg-pop') || e.target.closest('#cfg-open')) return;
2341
+ // 点面板外关闭设置(与 theme-pop 同一交互口径;面板内有自己的取消/保存,这里只兜底空白处)
2342
+ if ($('cfg-pop').style.display === 'block' && !e.target.closest('#cfg-actions')) closeCfgPop();
2343
+ });
2010
2344
  $('cfg-cancel').onclick = closeCfgPop;
2011
2345
 
2012
2346
  $('cfg-save').onclick = async () => {
@@ -2722,6 +3056,78 @@ $('eq-toggle').onclick = () => {
2722
3056
  $('eq-toggle').classList.toggle('active', open);
2723
3057
  };
2724
3058
 
3059
+ /* ================= 顶栏收纳:视图 / 更多 弹出菜单 =================
3060
+ 语言视图四态(译/对照/分屏)+ 重译收进「视图」下拉,深色/公式/设置收进「⋯」。
3061
+ 原按钮 DOM 保留(.tucked 隐藏):菜单项转发它们的 click,状态机
3062
+ (updateViewButtons / refreshZhState)零改动;菜单渲染只**读**原按钮态,
3063
+ 不在菜单里维护第二份状态。 */
3064
+ function closeBarMenus() {
3065
+ $('view-menu').hidden = true;
3066
+ }
3067
+ function viewMenuLabel() {
3068
+ if (viewMode === 'split') return '分屏';
3069
+ if (viewMode === 'dual') return '对照';
3070
+ if (viewMode === 'zh') return '中文';
3071
+ return '原文';
3072
+ }
3073
+ function syncViewMenu() {
3074
+ const btn = $('view-menu-btn'); if (!btn) return;
3075
+ const label = viewMenuLabel();
3076
+ btn.textContent = '视图:' + label + ' ▾';
3077
+ btn.classList.toggle('active', label !== '原文');
3078
+ const items = {
3079
+ zh: [zhVariant !== null, $('zh-toggle').disabled, $('zh-toggle').title],
3080
+ dual: [viewMode === 'dual', $('dual-toggle').disabled, $('dual-toggle').title],
3081
+ split: [viewMode === 'split', $('split-toggle').disabled, $('split-toggle').title],
3082
+ };
3083
+ for (const [act, [active, disabled, title]] of Object.entries(items)) {
3084
+ const el = $('view-menu').querySelector('[data-act="' + act + '"]');
3085
+ if (!el) continue;
3086
+ el.classList.toggle('active', !!active);
3087
+ el.disabled = !!disabled;
3088
+ if (title) el.title = title;
3089
+ }
3090
+ const origEl = $('view-menu').querySelector('[data-act="orig"]');
3091
+ if (origEl) origEl.classList.toggle('active', label === '原文');
3092
+ // 重译:与 refreshZhState 的 canRegen 同判据(有译文且空闲)
3093
+ const regenEl = $('view-menu').querySelector('[data-act="regen"]');
3094
+ if (regenEl) {
3095
+ regenEl.disabled = !((zhState.zh || zhState.dual) && !zhState.busy);
3096
+ regenEl.title = $('zh-regen').title;
3097
+ }
3098
+ }
3099
+
3100
+ function openBarMenu(menuId, btnId) {
3101
+ closeBarMenus();
3102
+ syncViewMenu();
3103
+ const menu = $(menuId), btn = $(btnId);
3104
+ menu.hidden = false;
3105
+ const br = $('bar').getBoundingClientRect(), r = btn.getBoundingClientRect();
3106
+ // 锚在**按钮正下方**而非 #bar 底部:窄窗口下顶栏 flex-wrap 换行会把 bar 撑到数百像素高,
3107
+ // 「bar 底部 + 6px」把菜单顶到视口外(实测 399px 宽 iframe → 菜单 y=960 > 视口 954,开了但看不见)
3108
+ menu.style.top = (r.bottom - br.top + 6) + 'px';
3109
+ menu.style.left = Math.max(4, Math.min(r.left - br.left, br.width - menu.offsetWidth - 4)) + 'px';
3110
+ }
3111
+ $('view-menu-btn').onclick = (e) => {
3112
+ e.stopPropagation();
3113
+ if ($('view-menu').hidden) openBarMenu('view-menu', 'view-menu-btn'); else closeBarMenus();
3114
+ };
3115
+ $('view-menu').onclick = (e) => {
3116
+ const b = e.target.closest('button'); if (!b) return;
3117
+ closeBarMenus();
3118
+ const act = b.dataset.act;
3119
+ if (act === 'orig') void setViewMode('orig');
3120
+ else if (act === 'zh') $('zh-toggle').click();
3121
+ else if (act === 'dual') $('dual-toggle').click();
3122
+ else if (act === 'split') $('split-toggle').click();
3123
+ else if (act === 'regen') $('zh-regen').click();
3124
+ };
3125
+ document.addEventListener('click', (e) => {
3126
+ if (e.target.closest('.bar-menu') || e.target.closest('#view-menu-btn')) return;
3127
+ closeBarMenus();
3128
+ });
3129
+ document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeBarMenus(); });
3130
+
2725
3131
  let lastMove = { x: -1, y: -1 };
2726
3132
  document.addEventListener('mousemove', (e) => {
2727
3133
  if (!eqHotEnabled()) { setEqHover(null); return; }
@@ -2860,7 +3266,11 @@ $('ask-send').onclick = async () => {
2860
3266
  : {};
2861
3267
  const r = await api('/ask', {
2862
3268
  method: 'POST', headers: { 'content-type': 'application/json' },
2863
- body: JSON.stringify({ ...current, question, selectedText: askSelection.text, page: askSelection.page, ...eq, ...(n ? { n } : {}) }),
3269
+ body: JSON.stringify({
3270
+ ...current, question, selectedText: askSelection.text, page: askSelection.page, ...eq, ...(n ? { n } : {}),
3271
+ // 默认「本篇」**不传 scope**(与改造前逐字节一致);只有明确切到专题时才传
3272
+ ...(askScopeMode() === 'topic' ? { scope: { kind: 'topic', topic: current.topic } } : {}),
3273
+ }),
2864
3274
  });
2865
3275
  askPop.style.display = 'none';
2866
3276
  toast(askSelection.kind === 'equation' ? `已引用公式并发送到 会话${r.n}` : `已发送到 会话${r.n},回答见对话区`);
@@ -3429,7 +3839,14 @@ $('sync-toggle').onclick = () => {
3429
3839
  /** 设置面板(dsh 设置 → 论文伴读)改了同一个键 → 阅读器立即反映(含重新打开同步时的一次性对齐)。
3430
3840
  * 只在值真的变了的时候动:storage 只对**其他**文档触发,这里也不回写(不回写就不会回声)。 */
3431
3841
  window.addEventListener('storage', (e) => {
3432
- if (!e || e.key !== SYNC_SCROLL_KEY) return;
3842
+ // 跨文档偏好同步的**唯一**入口(结构性红线:全脚本只挂一个 storage 监听,避免回声/双写)。
3843
+ // 按 key 分派:深色镜像 / 分屏同步滚动。两个分支都只在值真的变了时动,且都不回写。
3844
+ if (!e) return;
3845
+ if (e.key === THEME_MIRROR_KEY) {
3846
+ try { if (e.newValue) setThemeLocal(JSON.parse(e.newValue)); } catch (err) { /* 损坏镜像:忽略 */ }
3847
+ return;
3848
+ }
3849
+ if (e.key !== SYNC_SCROLL_KEY) return;
3433
3850
  const next = e.newValue !== '0';
3434
3851
  if (next === syncScroll) return;
3435
3852
  setSyncScroll(next, { persist: false });
@@ -3629,6 +4046,7 @@ async function bootstrap() {
3629
4046
  // 伴读会话里的跳转链接([重读第 N 页](…?page=N))经此直达目标页
3630
4047
  const pPage = +(params.get('page') || 0) || undefined;
3631
4048
  const pQ = params.get('q') || undefined;
4049
+ await loadThemeConfig(); // 深色配置(服务端唯一一份;失败自动降级到镜像)
3632
4050
  const lib = await api('/library');
3633
4051
  if (lib.topics.length === 0) {
3634
4052
  $('empty').style.display = 'block';
@@ -3642,7 +4060,11 @@ async function bootstrap() {
3642
4060
  if (last && lib.papers.some((p) => p.topic === last.topic && p.name === last.name)) target = last;
3643
4061
  else target = lib.papers[0];
3644
4062
  }
3645
- if (target) await openPaper(target.topic, target.name, { page: pPage, q: pQ });
4063
+ if (target) {
4064
+ current = target; // 范围记忆的键带 topic/name(避免跨论文串味)
4065
+ setAskScopeMode(askScopeMode());
4066
+ await openPaper(target.topic, target.name, { page: pPage, q: pQ });
4067
+ }
3646
4068
  }
3647
4069
  bootstrap().catch((e) => {
3648
4070
  $('empty').style.display = 'block';