@ggboy123/dsh-paper-reader 1.6.1 → 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; }
@@ -190,7 +212,66 @@
190
212
  .textLayer span.find-hit { background: rgba(255,214,0,.45); border-radius: 2px; }
191
213
  .textLayer span.find-hit.cur { background: rgba(255,146,0,.55); }
192
214
 
215
+ /* ---------- 笔记(划词标注 + 可移动笔记窗口) ----------
216
+ 标注用「百分比盒子 + 底部波浪底图」而不是给 span 加 text-decoration:一个选区常跨多个 span,
217
+ 加类会把整行都画上波浪线(与查找高亮同一条教训)。盒子层 pointer-events:none,
218
+ 悬停/点击靠坐标命中测试,不会挡住划词选字。 */
219
+ .noteLayer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
220
+ .note-under { position: absolute; border-radius: 2px; pointer-events: none;
221
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='4'%3E%3Cpath d='M0 3 Q2.25 .6 4.5 3 T9 3' fill='none' stroke='%232f6bff' stroke-width='1.1'/%3E%3C/svg%3E");
222
+ background-repeat: repeat-x; background-position: 0 100%; background-size: 9px 4px; }
223
+ .note-under.flash { background-color: rgba(47,107,255,.20); }
224
+ #note-tip { position: fixed; z-index: 58; display: none; max-width: 320px; background: var(--panel);
225
+ border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.18);
226
+ padding: 8px 10px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; pointer-events: none; }
227
+ #note-tip .tip-hint { display: block; margin-top: 4px; color: var(--text-2); font-size: 11px; }
228
+ /* 气泡里的「笔记 / 全局搜索」:与「译」并列的小动作按钮,不改变原提问链路 */
229
+ #ask-note, #ask-find { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-2); cursor: pointer; }
230
+ /* 笔记窗口:与查找窗同一套(可拖动 / 拖边框缩放 / 位置记忆)。列表与编辑器切换显示。 */
231
+ #note-window { position: fixed; z-index: 46; display: none; flex-direction: column; width: 330px; height: 360px;
232
+ min-width: 260px; min-height: 200px; background: var(--panel); border: 1px solid var(--border);
233
+ border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); overflow: hidden; }
234
+ #note-window.on { display: flex; }
235
+ #note-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; cursor: move; user-select: none;
236
+ border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 600; flex: none; }
237
+ #note-head .spacer, #note-actions .spacer { flex: 1; }
238
+ #note-headcount { font-weight: 400; color: var(--text-2); font-variant-numeric: tabular-nums; }
239
+ #note-list { flex: 1; overflow: auto; padding: 4px 8px 10px; }
240
+ .note-item { display: block; width: 100%; text-align: left; border: 1px solid var(--border); border-radius: 6px;
241
+ background: var(--bg); color: var(--text); padding: 6px 8px; margin: 5px 0; cursor: pointer; font: inherit; font-size: 12px; line-height: 1.5; }
242
+ .note-item:hover { border-color: var(--accent); }
243
+ .note-item .ni-meta { display: block; color: var(--accent); font-size: 11px; margin-bottom: 2px; }
244
+ .note-item .ni-meta .ni-time { float: right; color: var(--text-2); font-weight: 400; }
245
+ .note-item .ni-body { display: block; white-space: pre-wrap; word-break: break-word; }
246
+ .note-item .ni-quote { display: block; color: var(--text-2); font-size: 11px; margin-top: 3px;
247
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
248
+ #note-empty { padding: 14px 6px; color: var(--text-2); font-size: 12px; line-height: 1.6; }
249
+ #note-editor { display: none; flex-direction: column; flex: 1; min-height: 0; padding: 6px 8px 8px; }
250
+ #note-window.editing #note-list, #note-window.editing #note-empty { display: none; }
251
+ #note-window.editing #note-editor { display: flex; }
252
+ #note-quote { flex: none; max-height: 72px; overflow: auto; font-size: 11.5px; color: var(--text-2);
253
+ border-left: 3px solid var(--accent-soft); padding-left: 8px; margin-bottom: 6px; }
254
+ #note-body { flex: 1; min-height: 80px; width: 100%; resize: none; border: 1px solid var(--border); border-radius: 6px;
255
+ padding: 6px 8px; font: inherit; font-size: 12.5px; line-height: 1.6; background: var(--panel); color: var(--text); }
256
+ #note-actions { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex: none; }
257
+ .tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
258
+ #note-grip { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; z-index: 2; }
259
+ #note-grip::after { content: ''; position: absolute; right: 3px; bottom: 3px; width: 8px; height: 8px;
260
+ border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2); border-bottom-right-radius: 3px; opacity: .55; }
261
+ #note-grip-r { position: absolute; top: 34px; right: 0; bottom: 16px; width: 6px; cursor: ew-resize; z-index: 2; }
262
+ #note-grip-b { position: absolute; left: 0; right: 16px; bottom: 0; height: 6px; cursor: ns-resize; z-index: 2; }
263
+
193
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; }
194
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; }
195
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; }
196
277
  #ask-input { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; resize: none; }
@@ -220,11 +301,16 @@
220
301
 
221
302
  /* ---------- 翻译端点设置浮层 ---------- */
222
303
  /* 阅读器在窄 iframe 里,宽度要能收缩 */
223
- #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)); }
224
- #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; }
225
306
  #cfg-hint { font-size: 12px; color: var(--text-2); margin: 4px 0 2px; }
226
- #cfg-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 2px; }
227
- #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); }
228
314
  #cfg-model-hint, #cfg-source { font-size: 11.5px; color: var(--text-2); margin-top: 4px; line-height: 1.5; }
229
315
  #cfg-source:empty { display: none; }
230
316
  #cfg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
@@ -233,6 +319,26 @@
233
319
  #cfg-cancel { background: none; border: none; color: var(--text-2); cursor: pointer; }
234
320
 
235
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; }
236
342
  </style>
237
343
  </head>
238
344
  <body>
@@ -242,34 +348,46 @@
242
348
  <!-- 翻译进度条:只在 babeldoc 跑着时出现(宽度=overall,文字=阶段+百分比),
243
349
  窄列下先让位给按钮(flex:0 1 auto + min-width:0),别把控件挤出去 -->
244
350
  <span id="zh-prog" hidden><span class="track"><span class="fill"></span></span><span class="txt"></span></span>
245
- <button id="pdf-path" style="display:none" title="点击复制文件路径"></button>
246
- <button id="zh-toggle" class="tbtn" title="切换中文译文(没有译文时可生成)" style="display:none" data-icon="translate"></button>
247
- <button id="dual-toggle" class="tbtn" title="用 babeldoc 的中英对照 PDF(模式 A)" style="display:none" data-icon="columns">对照</button>
248
- <button id="split-toggle" class="tbtn" title="原文与中文版并排同步滚动(模式 B)" style="display:none" data-icon="split">分屏</button>
249
- <!-- 「同步滚动」开关(模式 B 的全局偏好):分屏控件旁,只在分屏下可见(模式 A/原文/译文都没有两个滚动条)。
250
- 状态换图标(sync / syncOff,与 mode-toggle 的 paged/scroll 同法)+ title 里 zh/en 说明状态;
251
- 与设置面板里的同一项共用 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>
252
361
  <button id="sync-toggle" class="tbtn" title="同步滚动 / Sync scroll:开(两列一起滚,点击关闭)" style="display:none" data-icon="sync"></button>
253
- <button id="zh-regen" class="tbtn" title="重新翻译:删除现有译文,用当前端点重跑(换模型后用)" style="display:none" data-icon="regen"></button>
254
- <button id="dl-btn" class="tbtn" title="下载 PDF" style="display:none" data-icon="download"></button>
255
- <!-- 在文中查找(Ctrl+F):入口紧挨下载,实际输入条是浮层,不占顶栏宽度 -->
256
- <button id="find-open" class="tbtn" title="在文中查找(Ctrl+F)" style="display:none" data-icon="search"></button>
257
- <span class="spacer"></span>
258
- <button id="mode-toggle" class="tbtn" title="切换 滚动/翻页模式" style="display:none" data-icon="paged"></button>
259
- <span id="pager" style="display:none">
260
- <button id="page-prev" class="tbtn" title="上一页" data-icon="prev"></button>
261
- <input id="page-input" type="text" inputmode="numeric" title="页码,回车跳转">
262
- <span id="page-total">/ ?</span>
263
- <button id="page-next" class="tbtn" title="下一页" data-icon="next"></button>
264
- </span>
265
- <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>
266
364
  <button id="zoom-out" class="tbtn" title="缩小" data-icon="minus"></button>
267
365
  <span id="zoom-label">100%</span>
268
366
  <button id="zoom-in" class="tbtn" title="放大" data-icon="plus"></button>
269
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>
270
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>
271
380
  <span id="ver" title="插件版本">__DPR_VERSION__</span>
272
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>
273
391
 
274
392
  <div id="main">
275
393
  <div id="split-wrap">
@@ -283,6 +401,14 @@
283
401
  <div id="pdf-pages-zh"></div>
284
402
  </div>
285
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>
286
412
  <div id="eq-panel">
287
413
  <h3>公式</h3>
288
414
  <div id="eq-meta"></div>
@@ -310,14 +436,51 @@
310
436
  <div id="find-grip-b" title="拖动改变高度"></div>
311
437
  <div id="find-grip" title="拖动调整大小"></div>
312
438
  </div>
439
+
440
+ <!-- 笔记窗口:与查找窗同一套交互(标题栏拖动 / 三边缩放 / 位置尺寸记忆)。
441
+ 列表态显示全部笔记,编辑态换成「引用 + 正文 + 保存/删除」。 -->
442
+ <div id="note-window" role="dialog" aria-label="笔记">
443
+ <div id="note-head">
444
+ <span>笔记</span>
445
+ <span id="note-headcount"></span>
446
+ <span class="spacer"></span>
447
+ <button id="note-new" class="tbtn mini" title="把当前选中的文字做成新笔记">+</button>
448
+ <button id="note-window-close" class="tbtn mini" title="关闭(Esc)">✕</button>
449
+ </div>
450
+ <div id="note-list"></div>
451
+ <div id="note-editor">
452
+ <div id="note-quote"></div>
453
+ <textarea id="note-body" placeholder="写下你的理解、疑问、和别处的联系…(⌘/Ctrl+Enter 保存)"></textarea>
454
+ <div id="note-actions">
455
+ <button id="note-delete" class="tbtn mini" title="删除这条笔记">删除</button>
456
+ <span class="spacer"></span>
457
+ <button id="note-cancel" class="tbtn mini">取消</button>
458
+ <button id="note-save" class="tbtn mini primary">保存</button>
459
+ </div>
460
+ </div>
461
+ <div id="note-grip-r" title="拖动改变宽度"></div>
462
+ <div id="note-grip-b" title="拖动改变高度"></div>
463
+ <div id="note-grip" title="拖动调整大小"></div>
464
+ </div>
313
465
  </div>
314
466
 
315
467
  <div id="ask-pop">
316
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>
317
478
  <textarea id="ask-input" rows="2" placeholder="围绕选中内容提问…"></textarea>
318
479
  <div id="ask-actions">
319
480
  <button id="ask-copy" style="display:none">复制 LaTeX</button>
320
481
  <button id="ask-translate" style="display:none" title="翻译选中内容(含公式时用 MinerU 的 LaTeX 还原)">译</button>
482
+ <button id="ask-note" style="display:none" title="给这段文字加一条笔记">笔记</button>
483
+ <button id="ask-find" style="display:none" title="在全文里查找这段文字">全局搜索</button>
321
484
  <button id="ask-cancel">取消</button>
322
485
  <button id="ask-send">提问</button>
323
486
  </div>
@@ -332,7 +495,7 @@
332
495
 
333
496
  <div id="cfg-pop">
334
497
  <h3>翻译端点</h3>
335
- <div id="cfg-hint">选预设供应商,或选「自定义」填任意 OpenAI 兼容端点(通义 / 本地 vLLM 等)。保存前会先测试连接。</div>
498
+ <div id="cfg-hint">选预设供应商,或选「自定义」填任意 OpenAI 兼容端点(通义 / 本地 vLLM 等)。OpenCode Go 需先在 OpenCode Console 订阅并复制 API Key。保存前会先测试连接。</div>
336
499
  <div id="cfg-source"></div>
337
500
  <label for="cfg-provider">供应商</label>
338
501
  <select id="cfg-provider"></select>
@@ -350,10 +513,64 @@
350
513
  </div>
351
514
  </div>
352
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
+
540
+ <!-- 笔记悬停提示:鼠标停在被标注文字上显示笔记内容 -->
541
+ <div id="note-tip"></div>
542
+
353
543
  <div id="toast"></div>
354
544
 
355
545
  <script>
356
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
+ })();
357
574
  /* ================= 基础 ================= */
358
575
  const $ = (id) => document.getElementById(id);
359
576
  /* 顶栏图标:统一的 24×24 描边图标集(stroke=currentColor,active/disabled 变色自动跟随按钮)。
@@ -377,10 +594,13 @@ const ICONS = {
377
594
  spin: '<path d="M21 12a9 9 0 1 1-6.219-8.56"/>',
378
595
  search: '<circle cx="11" cy="11" r="7"/><path d="m20.5 20.5-3.9-3.9"/>',
379
596
  close: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
597
+ note: '<path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/>',
598
+ ask: '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',
380
599
  };
381
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>`;
382
601
  // 静态按钮按 data-icon 注入一次;动态按钮(翻译/重翻/模式切换)在状态变化时用同一函数换图标
383
- document.querySelectorAll('#bar [data-icon], #find-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)));
384
604
  const api = (p, opts) => fetch('/paper-reader/api' + p, opts).then(async (r) => {
385
605
  if (!r.ok) {
386
606
  // 服务端错误体有两种:{error}(参数/权限)与 {reason}(zh/generate 的未启动原因,带完整说明)
@@ -401,12 +621,196 @@ function toast(msg, ms = 3200) {
401
621
  }
402
622
  function esc(s) { return s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])); }
403
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
+
404
805
  // 路径复制:与「复制 LaTeX」共用同一个 copyText(剪贴板写入只有一处实现,见文件末尾定义)
405
806
  $('pdf-path').onclick = async () => {
406
807
  const p = $('pdf-path').textContent;
407
808
  if (!p) return;
408
- toast((await copyText(p)) ? '路径已复制' : '复制失败,路径见按钮悬停提示');
809
+ toast((await copyText(p)) ? '路径已复制' : '复制失败,路径见状态文字悬停提示');
409
810
  };
811
+ // 路径收进状态文字:点击「name · N 页」即复制(pdf-path 已 tucked,title 带完整路径)
812
+ $('status').style.cursor = 'pointer';
813
+ $('status').onclick = () => $('pdf-path').click();
410
814
 
411
815
  let current = null; // { topic, name }
412
816
  let zhState = { zh: false, dual: false, busy: false };
@@ -447,11 +851,13 @@ async function openPaper(topic, name, opts = {}) {
447
851
  ? `${name} · ${meta.pageCount ?? '?'} 页`
448
852
  : `${name} · 未转录(提问时会自动转录)`;
449
853
  $('status').textContent = statusMeta;
450
- // 文件路径展示(点击复制):独立于 #status,翻译阶段的 phase 覆写不影响它
854
+ // 文件路径:不再占顶栏一行——挂在 #status 的 title(悬停可见)+ 点击 #status 复制;
855
+ // #pdf-path 按钮 tucked 隐藏,textContent 仍作为路径的唯一载体(复制逻辑读它)
451
856
  const pathBtn = $('pdf-path');
452
857
  pathBtn.textContent = meta.pdfPath || '';
453
- pathBtn.title = (meta.pdfPath || '') + '(点击复制)';
454
858
  pathBtn.style.display = meta.pdfPath ? '' : 'none';
859
+ $('status').title = meta.pdfPath ? `${meta.pdfPath}(点击复制)` : '';
860
+ setAskScopeMode(askScopeMode());
455
861
  await refreshZhState();
456
862
  // 恢复该论文上次的视图模式(持久化复用同一个键,取值域扩到 'split';见 §4.3)
457
863
  const saved = localStorage.getItem(variantKey(topic, name));
@@ -461,6 +867,9 @@ async function openPaper(topic, name, opts = {}) {
461
867
  $('zh-toggle').classList.toggle('active', zhVariant !== null);
462
868
  // 译文版页宽与原文不同(对照双栏≈2×),分屏每列只有一半宽 ⇒ 都先进适宽
463
869
  if (zhVariant || viewMode === 'split') { fitMode = true; fitBtn.classList.add('active'); }
870
+ // 笔记与公式索引都必须在首次 paintPage 之前到货:paintPage 直接按 notes.list 铺波浪线。
871
+ // 两者互不依赖,并行拉取;笔记读失败不阻塞 PDF(loadNotes 内部吞错并保留空列表)。
872
+ const notesReady = loadNotes().catch(() => { /* 读失败:本页只是没有波浪线,不影响读论文 */ });
464
873
  // 公式索引(MinerU content_list):**必须在 loadPdf 之前到货**——热区是在 paintPage 里
465
874
  // 按 eqIndex 铺的,先渲染会漏画/残留上一篇的矩形;又必须排在 zhVariant 定稿之后——
466
875
  // eqHotEnabled()/renderEqPanel() 都按 zhVariant 决定「译文视图关热区」。失败不影响打开文献。
@@ -468,12 +877,13 @@ async function openPaper(topic, name, opts = {}) {
468
877
  updateDlBtn();
469
878
  updateViewButtons();
470
879
  if (viewMode === 'split') {
880
+ await notesReady; // 分屏两列由 openSplit 安排渲染,这里只需保证笔记在首帧前就绪
471
881
  await openSplit(); // 内部自己拉原文 + -zh.pdf 两个文档
472
882
  } else {
473
883
  // R-02:原地换文献时**无条件**退掉分屏(幂等)——否则新论文有 -zh.pdf、而持久化视图又不是
474
884
  // split 时,refreshZhState 的回落守卫不触发,中文列会留着**上一篇**的 PDF(pdfDocZh 也不释放)。
475
885
  teardownSplit();
476
- await loadPdf(pdfUrl(zhVariant));
886
+ await loadPdf(pdfUrl(zhVariant), { beforePaint: notesReady });
477
887
  }
478
888
  if (opts.page) jumpTo(opts.page, opts.q); // 不 await:跳转内部自带「等页面渲出来」轮询
479
889
  }
@@ -483,13 +893,16 @@ async function openPaper(topic, name, opts = {}) {
483
893
  function updateDlBtn() {
484
894
  const btn = $('dl-btn');
485
895
  const findBtn = $('find-open');
896
+ const noteBtn = $('note-open');
486
897
  if (!current) {
487
898
  btn.style.display = 'none';
488
899
  if (findBtn) findBtn.style.display = 'none';
900
+ if (noteBtn) noteBtn.style.display = 'none';
489
901
  return;
490
902
  }
491
903
  btn.style.display = '';
492
904
  if (findBtn) findBtn.style.display = '';
905
+ if (noteBtn) noteBtn.style.display = '';
493
906
  btn.title = zhVariant === 'zh' ? '下载:纯中文版 PDF'
494
907
  : zhVariant === 'dual' ? '下载:中英对照版 PDF' : '下载:原文 PDF';
495
908
  }
@@ -1091,6 +1504,548 @@ window.dprFindDebug = () => {
1091
1504
  };
1092
1505
  };
1093
1506
 
1507
+ /* ================= 笔记(划词标注 + 可移动笔记窗口)=================
1508
+ 存储:服务端 `<论文>.notes.json`(与 `.study.json` 同目录 ⇒ 跟文献走、换浏览器不丢、将来也能被伴读读到)。
1509
+ 锚点:页号 + 「该页 DOM 文本层拼接串」里的字符区间。文本层的内容只由 PDF 决定(与缩放/模式无关),
1510
+ 所以偏移在重渲染后仍然有效 → 每次渲染完成按偏移重建 Range → 百分比盒子(蓝色波浪线)。
1511
+ 为什么不用给 span 加 text-decoration:一个选区常跨多个 span,加类会把整行都画上波浪线。
1512
+ 盒子层 pointer-events:none,悬停/点击靠坐标命中测试 —— 绝不挡住划词选字。 */
1513
+ const NOTE_WIN_KEY = 'dpr.noteWin';
1514
+ const NOTE_BODY_MAX = 20000;
1515
+ const notes = { list: [], shown: false, editing: null, isNew: true, armed: false, loading: false };
1516
+ let noteWin = { x: null, y: null, w: 330, h: 360 };
1517
+ const noteWinEl = $('note-window');
1518
+ const noteTipEl = $('note-tip');
1519
+ let noteArmTimer = 0;
1520
+ let noteHoverRaf = 0;
1521
+ let noteHoverId = null;
1522
+
1523
+ /* ---------- 窗口几何:与查找窗同一套(位置尺寸记在 localStorage) ---------- */
1524
+ function noteWinSave() {
1525
+ try {
1526
+ const r = noteWinEl.getBoundingClientRect();
1527
+ localStorage.setItem(NOTE_WIN_KEY, JSON.stringify({
1528
+ x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height),
1529
+ }));
1530
+ } catch { /* 隐私模式记不住:下次回到默认位置 */ }
1531
+ }
1532
+ function noteWinLoad() {
1533
+ if (!noteWinEl) return;
1534
+ try {
1535
+ const raw = JSON.parse(localStorage.getItem(NOTE_WIN_KEY) || 'null');
1536
+ if (raw) {
1537
+ if (Number.isFinite(raw.w)) noteWin.w = Math.max(260, Math.min(720, raw.w));
1538
+ if (Number.isFinite(raw.h)) noteWin.h = Math.max(200, raw.h);
1539
+ if (Number.isFinite(raw.x) && Number.isFinite(raw.y)) { noteWin.x = raw.x; noteWin.y = raw.y; }
1540
+ }
1541
+ } catch { /* 坏 JSON:用默认值 */ }
1542
+ }
1543
+ function noteWinPlace() {
1544
+ if (!noteWinEl) return;
1545
+ const w = noteWin.w;
1546
+ const h = Math.min(noteWin.h, Math.max(200, window.innerHeight - 40));
1547
+ let x = noteWin.x;
1548
+ let y = noteWin.y;
1549
+ if (x === null || y === null) {
1550
+ const btn = $('note-open');
1551
+ const r = btn ? btn.getBoundingClientRect() : null;
1552
+ if (r && r.width) { x = r.right - w; y = r.bottom + 6; }
1553
+ else { x = window.innerWidth - w - 26; y = 64; }
1554
+ }
1555
+ x = Math.max(8, Math.min(x, window.innerWidth - w - 8));
1556
+ y = Math.max(8, Math.min(y, window.innerHeight - h - 8));
1557
+ noteWinEl.style.width = w + 'px';
1558
+ noteWinEl.style.height = h + 'px';
1559
+ noteWinEl.style.left = Math.round(x) + 'px';
1560
+ noteWinEl.style.top = Math.round(y) + 'px';
1561
+ noteWin.x = Math.round(x);
1562
+ noteWin.y = Math.round(y);
1563
+ }
1564
+ function noteWinDrag(e) {
1565
+ if (e.button !== 0 || e.target.closest('button')) return;
1566
+ e.preventDefault();
1567
+ const start = { mx: e.clientX, my: e.clientY, x: noteWinEl.offsetLeft, y: noteWinEl.offsetTop };
1568
+ const move = (ev) => {
1569
+ noteWin.x = start.x + (ev.clientX - start.mx);
1570
+ noteWin.y = start.y + (ev.clientY - start.my);
1571
+ noteWinPlace();
1572
+ };
1573
+ const up = () => {
1574
+ window.removeEventListener('pointermove', move);
1575
+ window.removeEventListener('pointerup', up);
1576
+ window.removeEventListener('pointercancel', up);
1577
+ noteWinSave();
1578
+ };
1579
+ window.addEventListener('pointermove', move);
1580
+ window.addEventListener('pointerup', up);
1581
+ window.addEventListener('pointercancel', up);
1582
+ }
1583
+ /** 拖边缘/右下角改大小:dir = 'se'(角)| 'e'(右边缘)| 's'(下边缘) */
1584
+ function noteWinResize(e, dir) {
1585
+ if (e.button !== 0) return;
1586
+ e.preventDefault();
1587
+ e.stopPropagation();
1588
+ const start = { mx: e.clientX, my: e.clientY, w: noteWinEl.offsetWidth, h: noteWinEl.offsetHeight, x: noteWinEl.offsetLeft, y: noteWinEl.offsetTop };
1589
+ const move = (ev) => {
1590
+ if (dir !== 's') noteWin.w = Math.max(260, Math.min(window.innerWidth - 16, start.w + (ev.clientX - start.mx)));
1591
+ if (dir !== 'e') noteWin.h = Math.max(200, Math.min(window.innerHeight - 24, start.h + (ev.clientY - start.my)));
1592
+ noteWin.x = start.x;
1593
+ noteWin.y = start.y;
1594
+ noteWinPlace();
1595
+ };
1596
+ const up = () => {
1597
+ window.removeEventListener('pointermove', move);
1598
+ window.removeEventListener('pointerup', up);
1599
+ window.removeEventListener('pointercancel', up);
1600
+ noteWinSave();
1601
+ };
1602
+ window.addEventListener('pointermove', move);
1603
+ window.addEventListener('pointerup', up);
1604
+ window.addEventListener('pointercancel', up);
1605
+ }
1606
+
1607
+ /* ---------- 读写(服务端 <论文>.notes.json) ---------- */
1608
+ function notesQs() {
1609
+ return '?topic=' + encodeURIComponent(current.topic) + '&name=' + encodeURIComponent(current.name);
1610
+ }
1611
+ async function loadNotes() {
1612
+ notes.list = [];
1613
+ notes.editing = null;
1614
+ notes.loading = true;
1615
+ if (noteWinEl) noteWinEl.classList.remove('editing');
1616
+ noteClearLayers();
1617
+ renderNoteList();
1618
+ if (!current) { notes.loading = false; return; }
1619
+ const want = current.topic + '/' + current.name;
1620
+ try {
1621
+ const r = await api('/notes' + notesQs());
1622
+ if (!current || current.topic + '/' + current.name !== want) return; // 期间换了文献:丢弃
1623
+ notes.list = Array.isArray(r.notes) ? r.notes : [];
1624
+ } catch { /* 笔记读不出来不影响读论文 */ }
1625
+ notes.loading = false;
1626
+ renderNoteList();
1627
+ notesReapply();
1628
+ }
1629
+ /** 写一条(save)或删一条(delete);服务端返回整份笔记列表,客户端整体替换 */
1630
+ async function notesPost(action, note) {
1631
+ const body = { topic: current.topic, name: current.name, action };
1632
+ if (action === 'delete') body.id = note.id;
1633
+ else body.note = note;
1634
+ const r = await api('/notes', {
1635
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body),
1636
+ });
1637
+ notes.list = Array.isArray(r.notes) ? r.notes : notes.list;
1638
+ }
1639
+
1640
+ /* ---------- 锚点:选区 ⇄ 字符偏移 ---------- */
1641
+ /** 一页文本层的「拼接串 + 文本节点表」;at(off) 给 (文本节点, 节点内偏移),offsetOf(node,off) 反向换算。
1642
+ * 必须用文本节点:Range.setStart(元素, n) 里的 n 是子节点序号(查找高亮踩过这个坑)。 */
1643
+ function noteTextHay(pageDiv) {
1644
+ const tl = pageDiv && pageDiv.querySelector('.textLayer');
1645
+ if (!tl) return null;
1646
+ const nodes = [];
1647
+ const startOf = [];
1648
+ let hay = '';
1649
+ const walker = document.createTreeWalker(tl, NodeFilter.SHOW_TEXT);
1650
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
1651
+ const t = n.nodeValue || '';
1652
+ if (!t) continue;
1653
+ nodes.push(n);
1654
+ startOf.push(hay.length);
1655
+ hay += t;
1656
+ }
1657
+ if (!hay) return null;
1658
+ const at = (off) => {
1659
+ let lo = 0;
1660
+ let hi = startOf.length - 1;
1661
+ let idx = 0;
1662
+ while (lo <= hi) {
1663
+ const mid = (lo + hi) >> 1;
1664
+ if (startOf[mid] <= off) { idx = mid; lo = mid + 1; } else { hi = mid - 1; }
1665
+ }
1666
+ const node = nodes[idx];
1667
+ return [node, Math.max(0, Math.min(off - startOf[idx], node.nodeValue.length))];
1668
+ };
1669
+ const offsetOf = (node, off) => {
1670
+ const i = nodes.indexOf(node);
1671
+ return i < 0 ? null : startOf[i] + off;
1672
+ };
1673
+ return { hay, at, offsetOf, length: hay.length };
1674
+ }
1675
+ /** 把当前选区换算成 `{page,start,end,doc}`;换算不出来(扫描件/跨页/结构异常)返回 null */
1676
+ function noteAnchorFromSelection() {
1677
+ const sel = askSelection;
1678
+ if (!sel || !sel.range || !current) return null;
1679
+ const node = sel.range.startContainer;
1680
+ const el = node && (node.nodeType === 3 ? node.parentElement : node);
1681
+ const pageEl = el && el.closest ? el.closest('.page') : null;
1682
+ if (!pageEl) return null;
1683
+ const page = +(pageEl.dataset.page || 0) || 0;
1684
+ if (!page) return null;
1685
+ const hay = noteTextHay(pageEl);
1686
+ if (!hay) return null;
1687
+ const start = hay.offsetOf(sel.range.startContainer, sel.range.startOffset);
1688
+ const end = hay.offsetOf(sel.range.endContainer, sel.range.endOffset);
1689
+ if (start === null || end === null) return null;
1690
+ const a = Math.min(start, end);
1691
+ const b = Math.max(start, end);
1692
+ if (b - a < 1) return null;
1693
+ // 分屏时在中文列划的词,锚点算的是译文文本层的偏移 → 记下是哪一列,重画时只画回同一列
1694
+ const doc = pageEl.closest('#pdf-pages-zh') ? 'zh' : 'orig';
1695
+ return { page, start: a, end: b, doc, quote: sel.text.slice(0, 400) };
1696
+ }
1697
+
1698
+ /* ---------- 画波浪线(蓝色,选中文字下方) ---------- */
1699
+ function noteClearLayers() {
1700
+ document.querySelectorAll('.noteLayer').forEach((l) => l.remove());
1701
+ noteHideTip();
1702
+ }
1703
+ function notePaintPageDiv(div) {
1704
+ const tl = div && div.querySelector('.textLayer');
1705
+ const page = +(div && div.dataset && div.dataset.page) || 0;
1706
+ if (!tl || !page) return;
1707
+ const doc = div.closest && div.closest('#pdf-pages-zh') ? 'zh' : 'orig';
1708
+ const list = notes.list.filter((n) => n.anchor && n.anchor.page === page
1709
+ && n.anchor.end > n.anchor.start && (n.anchor.doc || 'orig') === doc);
1710
+ if (!list.length) return;
1711
+ const hay = noteTextHay(div);
1712
+ const rect = tl.getBoundingClientRect();
1713
+ if (!hay || !rect.width || !rect.height) return;
1714
+ // 同一页可能被重画多次(逐页渲染 + 收尾重放):先清掉这一页旧的装饰层,避免叠出两层波浪线
1715
+ const stale = div.querySelector(':scope > .noteLayer');
1716
+ if (stale) stale.remove();
1717
+ const pct = (v, base) => (v / base * 100).toFixed(3) + '%';
1718
+ const layer = document.createElement('div');
1719
+ layer.className = 'noteLayer';
1720
+ // 与 findLayer 同理:必须插在 textLayer **之前**,否则 paintPage 的 firstChild/lastChild 会取错元素
1721
+ div.insertBefore(layer, tl);
1722
+ for (const n of list) {
1723
+ const a = Math.max(0, Math.min(n.anchor.start, hay.length - 1));
1724
+ const b = Math.max(a + 1, Math.min(n.anchor.end, hay.length));
1725
+ const [na, oa] = hay.at(a);
1726
+ const [nb, ob] = hay.at(b);
1727
+ try {
1728
+ const rng = document.createRange();
1729
+ rng.setStart(na, oa);
1730
+ rng.setEnd(nb, ob);
1731
+ for (const r of rng.getClientRects()) {
1732
+ if (r.width < 0.6 || r.height < 0.6) continue; // 换行点产生的退化矩形
1733
+ const box = document.createElement('span');
1734
+ box.className = 'note-under';
1735
+ box.dataset.note = n.id;
1736
+ box.style.left = pct(r.left - rect.left, rect.width);
1737
+ box.style.top = pct(r.top - rect.top, rect.height);
1738
+ box.style.width = pct(r.width, rect.width);
1739
+ box.style.height = pct(r.height, rect.height);
1740
+ layer.appendChild(box);
1741
+ }
1742
+ } catch { /* 单条锚点算不出几何:跳过这条,列表里仍能看到 */ }
1743
+ }
1744
+ if (!layer.childElementCount) layer.remove();
1745
+ }
1746
+ /** 缩放/切模式/换文档会重建整个 DOM:重画全部波浪线 */
1747
+ function notesReapply() {
1748
+ noteClearLayers();
1749
+ if (!pdfDoc || !notes.list.length) return;
1750
+ document.querySelectorAll('#pdf-pages .page, #pdf-pages-zh .page').forEach((div) => notePaintPageDiv(div));
1751
+ }
1752
+
1753
+ /* ---------- 悬停提示 + 点击命中 ---------- */
1754
+ function noteById(id) {
1755
+ return notes.list.find((n) => n.id === id) || null;
1756
+ }
1757
+ function noteFindAt(x, y) {
1758
+ for (const box of document.querySelectorAll('.note-under')) {
1759
+ const r = box.getBoundingClientRect();
1760
+ if (x >= r.left - 1 && x <= r.right + 1 && y >= r.top - 1 && y <= r.bottom + 2) return box.dataset.note || null;
1761
+ }
1762
+ return null;
1763
+ }
1764
+ function noteHideTip() {
1765
+ if (noteTipEl) noteTipEl.style.display = 'none';
1766
+ }
1767
+ function noteShowTip(n, x, y) {
1768
+ if (!n || !noteTipEl) { noteHideTip(); return; }
1769
+ const body = String(n.body || '').trim();
1770
+ noteTipEl.textContent = '';
1771
+ const t = document.createElement('span');
1772
+ t.textContent = body.length > 400 ? body.slice(0, 400) + '…' : body;
1773
+ noteTipEl.appendChild(t);
1774
+ const hint = document.createElement('span');
1775
+ hint.className = 'tip-hint';
1776
+ hint.textContent = '点击编辑这条笔记';
1777
+ noteTipEl.appendChild(hint);
1778
+ noteTipEl.style.display = 'block';
1779
+ const r = noteTipEl.getBoundingClientRect();
1780
+ noteTipEl.style.left = Math.max(8, Math.min(x + 12, window.innerWidth - r.width - 8)) + 'px';
1781
+ noteTipEl.style.top = Math.max(8, Math.min(y + 16, window.innerHeight - r.height - 8)) + 'px';
1782
+ }
1783
+ $('main').addEventListener('mousemove', (e) => {
1784
+ if ((noteWinEl && noteWinEl.contains(e.target)) || (askPop && askPop.contains(e.target))) {
1785
+ noteHideTip();
1786
+ return;
1787
+ }
1788
+ if (noteHoverRaf) return;
1789
+ const x = e.clientX;
1790
+ const y = e.clientY;
1791
+ noteHoverRaf = requestAnimationFrame(() => {
1792
+ noteHoverRaf = 0;
1793
+ const id = noteFindAt(x, y);
1794
+ if (id === noteHoverId && id) { noteShowTip(noteById(id), x, y); return; }
1795
+ noteHoverId = id;
1796
+ if (id) noteShowTip(noteById(id), x, y);
1797
+ else noteHideTip();
1798
+ });
1799
+ });
1800
+
1801
+ /* ---------- 笔记窗口:列表态 / 编辑态 ---------- */
1802
+ function noteWinShow(on) {
1803
+ if (!noteWinEl) return;
1804
+ if (!on) {
1805
+ noteWinEl.classList.remove('on');
1806
+ notes.shown = false;
1807
+ noteHideTip();
1808
+ return;
1809
+ }
1810
+ noteWinEl.classList.add('on');
1811
+ notes.shown = true;
1812
+ noteWinPlace();
1813
+ renderNoteList();
1814
+ }
1815
+ function noteFmtTime(iso) {
1816
+ const d = iso ? new Date(iso) : null;
1817
+ if (!d || Number.isNaN(d.getTime())) return '';
1818
+ const p = (v) => String(v).padStart(2, '0');
1819
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
1820
+ }
1821
+ function renderNoteList() {
1822
+ const list = $('note-list');
1823
+ const head = $('note-headcount');
1824
+ if (!list || !head) return;
1825
+ head.textContent = notes.list.length ? `${notes.list.length} 条` : '';
1826
+ list.textContent = '';
1827
+ if (!notes.list.length) {
1828
+ const empty = document.createElement('div');
1829
+ empty.id = 'note-empty';
1830
+ empty.textContent = notes.loading
1831
+ ? '正在读取笔记…'
1832
+ : '还没有笔记。选中正文里的文字 → 点「笔记」,或点标题栏的 + 新建。笔记保存在这篇文献旁边(<论文>.notes.json),换浏览器也不会丢。';
1833
+ list.appendChild(empty);
1834
+ return;
1835
+ }
1836
+ // 按原文顺序列(没锚定的排最后)
1837
+ const sorted = notes.list.slice().sort((a, b) => {
1838
+ const pa = a.anchor && a.anchor.page ? a.anchor.page : 1e9;
1839
+ const pb = b.anchor && b.anchor.page ? b.anchor.page : 1e9;
1840
+ if (pa !== pb) return pa - pb;
1841
+ return ((a.anchor && a.anchor.start) || 0) - ((b.anchor && b.anchor.start) || 0);
1842
+ });
1843
+ const frag = document.createDocumentFragment();
1844
+ for (const n of sorted) {
1845
+ const btn = document.createElement('button');
1846
+ btn.type = 'button';
1847
+ btn.className = 'note-item';
1848
+ btn.dataset.id = n.id;
1849
+ btn.title = n.anchor && n.anchor.page ? `跳到第 ${n.anchor.page} 页` : '这条笔记没有可定位的原文位置';
1850
+ const meta = document.createElement('span');
1851
+ meta.className = 'ni-meta';
1852
+ meta.textContent = n.anchor && n.anchor.page ? `第 ${n.anchor.page} 页` : '未定位';
1853
+ const time = document.createElement('span');
1854
+ time.className = 'ni-time';
1855
+ time.textContent = noteFmtTime(n.updated || n.created);
1856
+ meta.appendChild(time);
1857
+ const bodyEl = document.createElement('span');
1858
+ bodyEl.className = 'ni-body';
1859
+ const body = String(n.body || '').trim();
1860
+ bodyEl.textContent = body.length > 220 ? body.slice(0, 220) + '…' : body;
1861
+ btn.appendChild(meta);
1862
+ btn.appendChild(bodyEl);
1863
+ if (n.quote) {
1864
+ const q = document.createElement('span');
1865
+ q.className = 'ni-quote';
1866
+ q.textContent = '「' + String(n.quote).replace(/\s+/g, ' ') + '」';
1867
+ btn.appendChild(q);
1868
+ }
1869
+ frag.appendChild(btn);
1870
+ }
1871
+ list.appendChild(frag);
1872
+ }
1873
+ function noteSetEditing(on) {
1874
+ notes.armed = false;
1875
+ const del = $('note-delete');
1876
+ if (del) { del.textContent = '删除'; del.classList.remove('primary'); }
1877
+ noteWinEl.classList.toggle('editing', !!on);
1878
+ if (!on) { notes.editing = null; notes.isNew = true; }
1879
+ }
1880
+ function noteStartEdit(note) {
1881
+ const isNew = !notes.list.some((n) => n.id === note.id);
1882
+ notes.editing = note;
1883
+ notes.isNew = isNew;
1884
+ $('note-quote').textContent = note.quote ? '「' + String(note.quote).replace(/\s+/g, ' ').slice(0, 300) + '」' : '(没有引用原文,只留正文)';
1885
+ $('note-body').value = note.body || '';
1886
+ $('note-delete').style.display = isNew ? 'none' : '';
1887
+ noteWinEl.classList.add('editing');
1888
+ noteWinShow(true);
1889
+ setTimeout(() => {
1890
+ const t = $('note-body');
1891
+ if (t) { t.focus(); t.setSelectionRange(t.value.length, t.value.length); }
1892
+ }, 30);
1893
+ }
1894
+ /** 划词「笔记」:带着引文和锚点直接进编辑态(保存前不落盘) */
1895
+ function noteCreateFromSelection() {
1896
+ const sel = askSelection;
1897
+ if (!sel || !current) { toast('先在正文里选中一段文字'); return; }
1898
+ const anchor = noteAnchorFromSelection();
1899
+ noteStartEdit({ quote: sel.text, anchor: anchor || undefined, body: '' });
1900
+ if (!anchor) toast('这段选区没能精确锚定:笔记会留在列表里,但不会画波浪线', 5000);
1901
+ }
1902
+ function noteCreateBlank() {
1903
+ const sel = askSelection;
1904
+ if (sel && sel.text) { noteCreateFromSelection(); return; }
1905
+ noteStartEdit({ quote: '', body: '' });
1906
+ }
1907
+ async function noteSave() {
1908
+ const body = $('note-body').value.trim();
1909
+ if (!body) { toast('笔记内容不能为空'); return; }
1910
+ if (!current) return;
1911
+ const old = notes.editing || {};
1912
+ const note = {
1913
+ id: old.id,
1914
+ quote: old.quote || '',
1915
+ anchor: old.anchor || undefined,
1916
+ body: body.slice(0, NOTE_BODY_MAX),
1917
+ created: old.created,
1918
+ updated: old.updated,
1919
+ };
1920
+ $('note-save').disabled = true;
1921
+ try {
1922
+ await notesPost('save', note);
1923
+ noteSetEditing(false);
1924
+ renderNoteList();
1925
+ notesReapply();
1926
+ toast('笔记已保存');
1927
+ } catch (e) { toast('保存失败:' + e.message, 6000); }
1928
+ $('note-save').disabled = false;
1929
+ }
1930
+ function noteArmDelete() {
1931
+ const btn = $('note-delete');
1932
+ if (!notes.editing || notes.isNew) return;
1933
+ if (!notes.armed) {
1934
+ notes.armed = true;
1935
+ btn.classList.add('primary');
1936
+ btn.textContent = '确认删除';
1937
+ btn.title = '再点一次确认删除这条笔记';
1938
+ clearTimeout(noteArmTimer);
1939
+ noteArmTimer = setTimeout(() => {
1940
+ notes.armed = false;
1941
+ btn.textContent = '删除';
1942
+ btn.classList.remove('primary');
1943
+ btn.title = '删除这条笔记';
1944
+ }, 3000);
1945
+ return;
1946
+ }
1947
+ clearTimeout(noteArmTimer);
1948
+ notes.armed = false;
1949
+ btn.textContent = '删除';
1950
+ btn.classList.remove('primary');
1951
+ void noteDoDelete(notes.editing);
1952
+ }
1953
+ async function noteDoDelete(note) {
1954
+ if (!note || !note.id) return;
1955
+ try {
1956
+ await notesPost('delete', note);
1957
+ noteSetEditing(false);
1958
+ renderNoteList();
1959
+ notesReapply();
1960
+ toast('笔记已删除');
1961
+ } catch (e) { toast('删除失败:' + e.message, 6000); }
1962
+ }
1963
+ async function noteGoto(note) {
1964
+ if (!note) return;
1965
+ const a = note.anchor;
1966
+ if (!a || !a.page) { toast('这条笔记没有可定位的原文位置'); return; }
1967
+ await findReadyPage(a.page);
1968
+ notesReapply();
1969
+ // 不把 id 拼进 CSS 选择器:服务端只截长度、不限字符集,id 含引号/括号会抛 DOMException。
1970
+ let box = null;
1971
+ for (const b of document.querySelectorAll('.note-under')) {
1972
+ if (b.dataset.note === note.id) { box = b; break; }
1973
+ }
1974
+ const target = box || origPageNode(a.page);
1975
+ if (target) target.scrollIntoView({ behavior: 'smooth', block: 'center' });
1976
+ if (box) {
1977
+ box.classList.add('flash');
1978
+ setTimeout(() => box.classList.remove('flash'), 900);
1979
+ }
1980
+ }
1981
+
1982
+ /* ---------- 气泡里的附加动作:笔记 / 全局搜索 ---------- */
1983
+ /** 「全局搜索」= 把选中文字塞进查找窗口并跳到第一处(与手打关键词同一条链路,不另做一套搜索) */
1984
+ function findSearchText(text) {
1985
+ const q = String(text || '').replace(/\s+/g, ' ').trim();
1986
+ if (!q) { toast('没有可搜索的文字'); return; }
1987
+ const use = q.length > 120 ? q.slice(0, 120) : q;
1988
+ findInputEl.value = use;
1989
+ findWinShow(true);
1990
+ void findRun(use).then(() => findGoto(0)).catch(() => { /* 索引失败:列表里会有说明 */ });
1991
+ }
1992
+ $('ask-find').onclick = () => {
1993
+ askPop.style.display = 'none';
1994
+ if (askSelection) findSearchText(askSelection.text);
1995
+ };
1996
+ $('ask-note').onclick = () => {
1997
+ askPop.style.display = 'none';
1998
+ noteCreateFromSelection();
1999
+ };
2000
+
2001
+ /* ---------- 接线 ---------- */
2002
+ $('note-open').onclick = () => {
2003
+ if (!current) return;
2004
+ if (noteWinEl.classList.contains('on') && !noteWinEl.classList.contains('editing')) { noteWinShow(false); return; }
2005
+ noteSetEditing(false);
2006
+ noteWinShow(true);
2007
+ };
2008
+ $('note-window-close').onclick = () => { noteSetEditing(false); noteWinShow(false); };
2009
+ $('note-new').onclick = () => noteCreateBlank();
2010
+ $('note-save').onclick = () => void noteSave();
2011
+ $('note-cancel').onclick = () => noteSetEditing(false);
2012
+ $('note-delete').onclick = () => noteArmDelete();
2013
+ $('note-list').addEventListener('click', (e) => {
2014
+ const btn = e.target.closest ? e.target.closest('.note-item') : null;
2015
+ if (!btn) return;
2016
+ void noteGoto(noteById(btn.dataset.id));
2017
+ });
2018
+ $('note-body').addEventListener('keydown', (e) => {
2019
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { e.preventDefault(); void noteSave(); }
2020
+ else if (e.key === 'Escape') { e.preventDefault(); noteSetEditing(false); }
2021
+ });
2022
+ // 全局 Esc:标题栏写着「关闭(Esc)」就必须真的能关。编辑态里先退出编辑(上面的 textarea
2023
+ // 处理器已 preventDefault,这里靠 defaultPrevented 避免同一次按键把窗口也一起关掉)。
2024
+ document.addEventListener('keydown', (e) => {
2025
+ if (e.key !== 'Escape' || e.defaultPrevented) return;
2026
+ if (!noteWinEl || !noteWinEl.classList.contains('on')) return;
2027
+ if (noteWinEl.classList.contains('editing')) noteSetEditing(false);
2028
+ else noteWinShow(false);
2029
+ });
2030
+ $('note-head').addEventListener('pointerdown', noteWinDrag);
2031
+ $('note-grip').addEventListener('pointerdown', (e) => noteWinResize(e, 'se'));
2032
+ $('note-grip-r').addEventListener('pointerdown', (e) => noteWinResize(e, 'e'));
2033
+ $('note-grip-b').addEventListener('pointerdown', (e) => noteWinResize(e, 's'));
2034
+ window.addEventListener('resize', () => { if (noteWinEl.classList.contains('on')) noteWinPlace(); });
2035
+ $('pdf-pane').addEventListener('scroll', () => { noteHideTip(); }, { passive: true });
2036
+ noteWinLoad();
2037
+
2038
+ /** 排查用:控制台执行 dprNotesDebug() 看笔记状态(波浪线不显示时先看 boxes) */
2039
+ window.dprNotesDebug = () => ({
2040
+ paper: current ? current.topic + '/' + current.name : null,
2041
+ notes: notes.list.length,
2042
+ anchored: notes.list.filter((n) => n.anchor).length,
2043
+ boxes: document.querySelectorAll('.note-under').length,
2044
+ layers: document.querySelectorAll('.noteLayer').length,
2045
+ editing: notes.editing ? notes.editing.id || '(new)' : null,
2046
+ windowOpen: !!(noteWinEl && noteWinEl.classList.contains('on')),
2047
+ });
2048
+
1094
2049
  /* ================= 中英切换 ================= */
1095
2050
  /** 翻译进度条(只在 busy 时出现):宽度跟着后端 progress.overall,文字给阶段+百分比。 */
1096
2051
  function updateZhProgress() { const box = $('zh-prog');
@@ -1182,6 +2137,7 @@ function updateViewButtons() {
1182
2137
  // 「同步滚动」开关:与三个视图控件同一个状态机(一处决定所有按钮的可见性/文案/态);
1183
2138
  // 仅分屏下可见 —— 模式 A/原文/译文只有一个滚动条,开关无意义
1184
2139
  updateSyncToggle();
2140
+ try { syncViewMenu(); } catch { /* 初始化次序未到(菜单函数在脚本更后方,事件驱动后即正常) */ }
1185
2141
  }
1186
2142
 
1187
2143
  $('zh-toggle').onclick = async () => {
@@ -1313,6 +2269,9 @@ const PROVIDERS = [
1313
2269
  { id: 'deepseek', name: 'DeepSeek', baseUrl: 'https://api.deepseek.com', models: ['deepseek-v4-pro', 'deepseek-flash'] },
1314
2270
  { id: 'glm', name: '智谱 GLM', baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4', models: ['glm-5.3-flash', 'glm-5.3', 'glm-4.6'] },
1315
2271
  { id: 'kimi', name: 'Kimi', baseUrl: 'https://api.kimi.com/coding/v1', models: ['k3'] },
2272
+ // OpenCode Go:订阅后到 OpenCode Console 复制 API Key;模型列表以控制台为准(此处只做输入建议)。
2273
+ // 服务端会对 opencode.ai 的请求自带 x-opencode-session(见 src/opencode.ts)。
2274
+ { id: 'opencode', name: 'OpenCode Go', baseUrl: 'https://opencode.ai/inference/go/openai/v1', models: ['deepseek-v4.1-flash', 'glm-5.3-flash', 'kimi-k3.1-pro', 'qwen3.8-flash', 'minimax-m3.1-flash'] },
1316
2275
  ];
1317
2276
  const normUrl = (u) => (u || '').trim().replace(/\/+$/, '');
1318
2277
  // 按 baseUrl 反查预设(打开表单时回显选中项);查不到就是 custom
@@ -1339,6 +2298,7 @@ let cfgRetryForce = false; // 待重试的是不是「重翻」(regen 图标
1339
2298
  let cfgRetryTranslate = false; // 待重试的是不是「划词翻译」(点「译」发现没配端点 → 填完自动重试这次翻译)
1340
2299
 
1341
2300
  async function openCfgPop(retryGenerate) {
2301
+ $('theme-pop').style.display = 'none'; // 与深色面板互斥:同时只开一个
1342
2302
  cfgRetryGenerate = Boolean(retryGenerate);
1343
2303
  let cfg;
1344
2304
  try {
@@ -1370,7 +2330,17 @@ async function openCfgPop(retryGenerate) {
1370
2330
  }
1371
2331
  function closeCfgPop() { $('cfg-pop').style.display = 'none'; cfgRetryGenerate = false; cfgRetryForce = false; cfgRetryTranslate = false; }
1372
2332
 
1373
- $('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
+ });
1374
2344
  $('cfg-cancel').onclick = closeCfgPop;
1375
2345
 
1376
2346
  $('cfg-save').onclick = async () => {
@@ -1449,6 +2419,8 @@ async function loadPdf(url, opts = {}) {
1449
2419
  // 翻页控件与模式切换按钮:文档就绪后才出现
1450
2420
  $('pager').style.display = '';
1451
2421
  $('mode-toggle').style.display = '';
2422
+ // 笔记请求与 PDF 文档加载并行;首次渲染前才等它(见 openPaper 的 beforePaint)
2423
+ if (opts.beforePaint) await opts.beforePaint;
1452
2424
  // 分屏(模式 B)自己安排两列的渲染与适宽:这里只把原文文档装上,不触发单列渲染
1453
2425
  if (opts.deferRender) return;
1454
2426
  if (fitMode) { fitToWidth(); return; } // fitToWidth 内部 setZoom → rerender
@@ -1505,13 +2477,18 @@ async function paintPage(page, div, viewport, token) {
1505
2477
  // 少了这一行,被抢占的收尾会把**上一档缩放**的几何写回 EQ_BY_PAGE → 点击热区整体偏移。
1506
2478
  if (token !== renderToken) return;
1507
2479
  paintEqLayer(div, viewport, +div.dataset.page);
2480
+ // 笔记波浪线:滚动模式懒加载、翻页模式单页渲染时也要画,不能只靠 rerender 收尾那一次
2481
+ notePaintPageDiv(div);
1508
2482
  }
1509
2483
 
1510
2484
  /** 当前模式的全量重渲入口:缩放/DPR/换文档/换变体统一走这里。
1511
2485
  * 分屏(模式 B)是第三套布局,转到 renderSplit();renderPaged/renderAllPages 的既有语义**不变**。 */
1512
2486
  function rerender() {
1513
- // 渲染完成后再补画查找高亮:缩放/切模式把 DOM 整个重建,旧的高亮层随之消失。
1514
- const done = () => { try { findReapply(); } catch { /* 高亮是装饰,失败不影响阅读 */ } };
2487
+ // 渲染完成后再补画查找高亮与笔记波浪线:缩放/切模式把 DOM 整个重建,旧的装饰层随之消失。
2488
+ const done = () => {
2489
+ try { findReapply(); } catch { /* 高亮是装饰,失败不影响阅读 */ }
2490
+ try { notesReapply(); } catch { /* 同上 */ }
2491
+ };
1515
2492
  if (viewMode === 'split') return renderSplit().then(done);
1516
2493
  return (pageMode === 'paged' ? renderPaged() : renderAllPages()).then(done);
1517
2494
  }
@@ -2079,6 +3056,78 @@ $('eq-toggle').onclick = () => {
2079
3056
  $('eq-toggle').classList.toggle('active', open);
2080
3057
  };
2081
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
+
2082
3131
  let lastMove = { x: -1, y: -1 };
2083
3132
  document.addEventListener('mousemove', (e) => {
2084
3133
  if (!eqHotEnabled()) { setEqHover(null); return; }
@@ -2108,6 +3157,10 @@ function showAskPop(o) {
2108
3157
  && (askSelection.doc ?? 'orig') === 'orig'
2109
3158
  && askSelection.text.length <= MAX_SELECTION_CHARS
2110
3159
  ? 'inline-block' : 'none';
3160
+ // 笔记 / 全局搜索:只对文字选区出现(公式引用没有可标注/可搜索的正文)
3161
+ const textSel = !!(askSelection && askSelection.kind === 'text');
3162
+ $('ask-note').style.display = textSel ? 'inline-block' : 'none';
3163
+ $('ask-find').style.display = textSel ? 'inline-block' : 'none';
2111
3164
  hideTrPop(); // 新选区/新引用出现即收起上一个译文气泡(同一锚点必然重叠)
2112
3165
  invalidateTranslate(); // R-01:新选区/新引用必须让在飞请求失效,否则旧译文会盖到新锚点上
2113
3166
  askPop.style.display = 'block';
@@ -2122,6 +3175,7 @@ document.addEventListener('mousedown', (e) => { downPt = { x: e.clientX, y: e.cl
2122
3175
 
2123
3176
  document.addEventListener('mouseup', (e) => {
2124
3177
  if (askPop.contains(e.target)) return;
3178
+ if (noteWinEl && noteWinEl.contains(e.target)) return;
2125
3179
  setTimeout(() => {
2126
3180
  const moved = downPt ? Math.abs(e.clientX - downPt.x) + Math.abs(e.clientY - downPt.y) > 4 : false;
2127
3181
  downPt = null;
@@ -2130,6 +3184,12 @@ document.addEventListener('mouseup', (e) => {
2130
3184
  if (!text || !current) {
2131
3185
  // 无选区(或没有当前文献)时才尝试公式点击 —— 有选区时「划词提问」优先,绝不抢。
2132
3186
  if (!text && !moved && current) {
3187
+ // 点在被标注的文字上 → 直接编辑那条笔记(笔记优先于公式热区)
3188
+ const nid = noteFindAt(e.clientX, e.clientY);
3189
+ if (nid) {
3190
+ const n = noteById(nid);
3191
+ if (n) { askPop.style.display = 'none'; noteStartEdit(n); return; }
3192
+ }
2133
3193
  const hit = hitTestFormula(e);
2134
3194
  if (hit) { citeFormula(hit.eq, e.clientX, e.clientY + 6); return; }
2135
3195
  }
@@ -2155,7 +3215,9 @@ document.addEventListener('mouseup', (e) => {
2155
3215
  const r0 = sel.getRangeAt(0);
2156
3216
  if (r0 && typeof r0.cloneRange === 'function') askSelection.range = r0.cloneRange();
2157
3217
  } catch { /* 选区已失效:保持无 range */ }
2158
- showAskPop({ quote: text, x: e.clientX, y: range.bottom + 8 });
3218
+ // 划词后**直接**弹回 v1.6.0 的「选中即问」气泡(E11/R-01/R-07 与 docs/features.md 的契约);
3219
+ // 笔记 / 全局搜索作为气泡里的小按钮,不再多一层菜单。
3220
+ showAskPop({ quote: text, x: e.clientX, y: Math.min(range.bottom + 8, window.innerHeight - 60) });
2159
3221
  }, 10);
2160
3222
  });
2161
3223
  document.addEventListener('mousedown', (e) => { if (!askPop.contains(e.target)) askPop.style.display = 'none'; });
@@ -2204,7 +3266,11 @@ $('ask-send').onclick = async () => {
2204
3266
  : {};
2205
3267
  const r = await api('/ask', {
2206
3268
  method: 'POST', headers: { 'content-type': 'application/json' },
2207
- 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
+ }),
2208
3274
  });
2209
3275
  askPop.style.display = 'none';
2210
3276
  toast(askSelection.kind === 'equation' ? `已引用公式并发送到 会话${r.n}` : `已发送到 会话${r.n},回答见对话区`);
@@ -2773,7 +3839,14 @@ $('sync-toggle').onclick = () => {
2773
3839
  /** 设置面板(dsh 设置 → 论文伴读)改了同一个键 → 阅读器立即反映(含重新打开同步时的一次性对齐)。
2774
3840
  * 只在值真的变了的时候动:storage 只对**其他**文档触发,这里也不回写(不回写就不会回声)。 */
2775
3841
  window.addEventListener('storage', (e) => {
2776
- 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;
2777
3850
  const next = e.newValue !== '0';
2778
3851
  if (next === syncScroll) return;
2779
3852
  setSyncScroll(next, { persist: false });
@@ -2973,6 +4046,7 @@ async function bootstrap() {
2973
4046
  // 伴读会话里的跳转链接([重读第 N 页](…?page=N))经此直达目标页
2974
4047
  const pPage = +(params.get('page') || 0) || undefined;
2975
4048
  const pQ = params.get('q') || undefined;
4049
+ await loadThemeConfig(); // 深色配置(服务端唯一一份;失败自动降级到镜像)
2976
4050
  const lib = await api('/library');
2977
4051
  if (lib.topics.length === 0) {
2978
4052
  $('empty').style.display = 'block';
@@ -2986,7 +4060,11 @@ async function bootstrap() {
2986
4060
  if (last && lib.papers.some((p) => p.topic === last.topic && p.name === last.name)) target = last;
2987
4061
  else target = lib.papers[0];
2988
4062
  }
2989
- 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
+ }
2990
4068
  }
2991
4069
  bootstrap().catch((e) => {
2992
4070
  $('empty').style.display = 'block';