dsh-rank-scan 0.5.0 → 0.5.2

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/README.md CHANGED
@@ -18,7 +18,7 @@ DeepSeek Harness 扫榜插件:定时 + 按需采集多站小说榜单,算变
18
18
 
19
19
  ```sh
20
20
  dsh plugin --profile desktop add github:kilo-s/dsh-rank-scan
21
- # 钉版本:github:kilo-s/dsh-rank-scan#v0.5.0
21
+ # 钉版本:github:kilo-s/dsh-rank-scan#v0.5.2
22
22
  ```
23
23
 
24
24
  仓库不含编译产物,这条命令会在安装时现场构建 `lib/`。首次可能被 pnpm 拦下构建脚本(它会打印要放行的键,加进 `allowBuilds` 后重跑即可),细节见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
@@ -37,14 +37,14 @@ dsh plugin --profile desktop add "<tgz 的完整路径>"
37
37
 
38
38
  ```sh
39
39
  dsh plugin --profile desktop add dsh-rank-scan
40
- # 钉版本:dsh-rank-scan@0.5.0
40
+ # 钉版本:dsh-rank-scan@0.5.2
41
41
  ```
42
42
 
43
43
  npm 上那份是 CI 从源码构建的(包内自带 `lib/`,发布带 `--provenance` 签名)——装的时候不用再编译,也不会被 pnpm 的 `allowBuilds` 拦下。面板的「检查更新」读的就是 npm 上的版本号。
44
44
 
45
45
  **验证**:重开 DSH 后左侧栏会话列表下方应出现「扫榜」入口;或访问 `http://127.0.0.1:19387/api/rank-scan/health`,返回 `{ok:true,...}` 即通。
46
46
 
47
- **更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.5.0**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
47
+ **更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.5.2**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
48
48
 
49
49
  **卸载**:`dsh plugin --profile desktop remove dsh-rank-scan`。数据目录 `~/.dsh/data/rank-scan` 会保留,要彻底清理自行删除;脚本化卸载与 patch 安全口径见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
50
50
 
package/lib/client.js CHANGED
@@ -1,3 +1,8 @@
1
+ /* ---- parts/00-head.js ---- */
2
+ /**
3
+ * 00-head.js:文件头、__ModuleLoader__.load 入口、React/h/API 常量与 jget/jpost/readResponse 请求层。依赖:无。不要放组件或页面逻辑。
4
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
5
+ */
1
6
  /**
2
7
  * dsh-rank-scan — 面板(手写 bundle,零依赖;只用平台提供的 react)。
3
8
  * 2026-10-14 重写:可拖动/可缩放浮窗(位置尺寸本地记忆);概览单行汇总;异常榜折叠;行内详情卡。
@@ -153,6 +158,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
153
158
  * 颜色优先读 DSH 宿主的 --dsw-alias-*(亮/暗主题各自解析),再退到旧版 --dsh-* 与静态兜底;
154
159
  * 兜底只为了在宿主变量缺失时不至于透明或白底白字,不是第二套主题。
155
160
  */
161
+ /* ---- parts/10-tokens.js ---- */
162
+ /**
163
+ * 10-tokens.js:设计令牌 T/C、主题变量、wash 与 ensureStyle 样式注入。依赖 00。不要放业务组件。
164
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
165
+ */
156
166
  const T = {
157
167
  surface: 'var(--dsw-alias-bg-layer-1, var(--dsh-surface, #fff))',
158
168
  surface2: 'var(--dsw-alias-bg-layer-2, var(--dsh-fill, rgba(128,128,128,.06)))',
@@ -222,6 +232,12 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
222
232
  '.rs-toast-x:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
223
233
  '[data-rank-scan-win] tbody tr:hover td{background:' + T.subtle + '}',
224
234
  '[data-rank-scan-win] a:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
235
+ '.rs-th-sort{border:none;background:transparent;padding:0;font:inherit;font-weight:600;cursor:pointer;color:inherit;display:inline-flex;align-items:center;gap:3px}',
236
+ '.rs-th-sort:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
237
+ '.rs-sort-arrow{opacity:0;color:' + T.muted + ';font-size:10px;line-height:1}',
238
+ '.rs-th-sort:hover .rs-sort-arrow,.rs-th-sort:focus-visible .rs-sort-arrow{opacity:1}',
239
+ '.rs-sort-arrow.is-on{opacity:1;color:' + T.accent + ';font-weight:600}',
240
+ '[data-rank-scan-win] [data-row-idx]:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:-2px}',
225
241
  ].join('\n')
226
242
  document.head.appendChild(el)
227
243
  }
@@ -268,6 +284,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
268
284
  input: { padding: '3px 6px', fontSize: T.fs.s, borderRadius: T.r.s, border: '1px solid ' + T.border, background: 'transparent', color: 'inherit' },
269
285
  }
270
286
  /** 统一提示条:三种语气只差颜色,形状一致;错误用 role=alert 让读屏器打断 */
287
+ /* ---- parts/20-ui-kit.js ---- */
288
+ /**
289
+ * 20-ui-kit.js:通用 UI:Banner、Toast、PopMenu、Section、格式化/状态/列宽工具、useRect。依赖 10。不要放整页页签。
290
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
291
+ */
271
292
  function Banner(props) {
272
293
  const role = props.live === false ? null : (props.tone === 'error' ? 'alert' : 'status')
273
294
  return h('div', { className: 'rs-banner is-' + (props.tone || 'info'), role: role },
@@ -778,6 +799,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
778
799
  * 旧对象没有 filters,BookmarksTab 里一行 f.q 就把整个页签打成错误边界。
779
800
  * 所以每次取用都先 healStore() 按对象补,不管它由哪一代定义创建。
780
801
  */
802
+ /* ---- parts/25-bookmark-star.js ---- */
803
+ /**
804
+ * 25-bookmark-star.js:书签本地 store 的 healStore 与 BookmarkStar 小部件。依赖 10/20。不要放书签页签。
805
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
806
+ */
781
807
  const healStore = function (s) {
782
808
  if (!s || typeof s !== 'object') return s
783
809
  if (!s.filters || typeof s.filters !== 'object') s.filters = { q: '', site: '', folder: '', tag: '' }
@@ -945,6 +971,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
945
971
  * ③ 组件卸载(收起浮窗 / 热重载)。
946
972
  * 旧写法只处理 ①:②③ 之后每次鼠标移动都还在改一个已经卸载的浮窗的 rect。
947
973
  */
974
+ /* ---- parts/30-window.js ---- */
975
+ /**
976
+ * 30-window.js:浮窗拖拽/缩放:useWindowDrag、DragBar、ResizeHandle。依赖 10/20。不要放数据逻辑。
977
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
978
+ */
948
979
  function useWindowDrag() {
949
980
  const active = React.useRef(null)
950
981
  const stop = React.useCallback(function () {
@@ -1025,6 +1056,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1025
1056
  }
1026
1057
 
1027
1058
  /** 字节 → 人话(数据目录占用用;保留 1 位小数,够看趋势就行) */
1059
+ /* ---- parts/40-overview.js ---- */
1060
+ /**
1061
+ * 40-overview.js:概览页:fmtBytes、StatCard、SectionHeader、nextPlanOf、Overview。依赖 20。不要放设置/榜单页。
1062
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
1063
+ */
1028
1064
  const fmtBytes = (n) => {
1029
1065
  if (n == null || !isFinite(n)) return '—'
1030
1066
  const u = ['B', 'KB', 'MB', 'GB']
@@ -1509,6 +1545,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1509
1545
  * 设置草稿 vs 已保存快照的差异(纯函数)。
1510
1546
  * captures 按集合比较(顺序不算变化);siteTimes 按字段比较。返回人类可读的分组名;空数组 = 干净。
1511
1547
  */
1548
+ /* ---- parts/50-settings.js ---- */
1549
+ /**
1550
+ * 50-settings.js:设置页:settingsDiff/retention/settingsSavedFrom、SettingsTab、VersionRow。依赖 10/20。不要放榜单页。
1551
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
1552
+ */
1512
1553
  const settingsDiff = function (saved, draft) {
1513
1554
  const out = []
1514
1555
  if (!saved || !draft) return out
@@ -2106,6 +2147,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2106
2147
  h('button', { className: 'rs-btn', disabled: busy !== '', onClick: function () { refresh() } }, '重新检查')))
2107
2148
  }
2108
2149
 
2150
+ /* ---- parts/55-board-cell.js ---- */
2151
+ /**
2152
+ * 55-board-cell.js:榜单表格单元格 cell、榜名记忆与 boardLabel。依赖 10/20。不要放 BoardTab 本体。
2153
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2154
+ */
2109
2155
  function cell(c, r) {
2110
2156
  const k = c.key
2111
2157
  const ex = r.extra || {}
@@ -2204,6 +2250,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2204
2250
  return BOARD_NAMES[id] || (id || '—')
2205
2251
  }
2206
2252
 
2253
+ /* ---- parts/60-bookmarks.js ---- */
2254
+ /**
2255
+ * 60-bookmarks.js:书签页:bookKeyOf、DetailBookmarkEditor、BookmarksTab。依赖 20/25。不要放榜单页。
2256
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2257
+ */
2207
2258
  function bookKeyOf(boardId, key) {
2208
2259
  const id = String(key == null ? '' : key).trim()
2209
2260
  if (!id) return ''
@@ -2604,6 +2655,57 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2604
2655
  * · 状态带一行写清:数据日期 · 源数据日期 · 对比基准(隔几天)· 跨期不可比
2605
2656
  * ★ 2026-10-22(B):同一天重扫会静默重读,且不重置站/榜/日期/排序/详情。
2606
2657
  */
2658
+ /* ---- parts/70-board.js ---- */
2659
+ /**
2660
+ * 70-board.js:榜单页:BoardTab(选择器、详情、操作条、本榜设置、日期回看)。依赖 20/55。不要放 Panel。
2661
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2662
+ */
2663
+ /**
2664
+ * 第六步(0.5.2):榜单表头的排序 / 行键盘用的纯函数。
2665
+ * 只消费宿主已经给出的 columns / sortOptions,不做客户端排序,也不新增排序方式。
2666
+ */
2667
+ const sortableCols = function (cols, sortOptions, defKey, defDir) {
2668
+ const values = (sortOptions || []).map(function (o) { return o && o.value }).filter(function (v) { return !!v })
2669
+ return (cols || []).filter(function (c) {
2670
+ return c && (values.indexOf(c.key) >= 0 || (!!defKey && c.key === defKey))
2671
+ }).map(function (c) {
2672
+ return { key: c.key, dir: c.key === defKey ? (defDir || 'descending') : 'descending' }
2673
+ })
2674
+ }
2675
+ const nextSort = function (cur, key, defKey) {
2676
+ if (key === defKey) return ''
2677
+ return cur === key ? '' : key
2678
+ }
2679
+ const normalizeSortPref = function (v) { return v === 'rank' ? '' : (v || '') }
2680
+ /** 只给行号,详情行不参与;n 是数据行数量 */
2681
+ const nextRowIdx = function (i, key, n) {
2682
+ const last = Math.max(0, Number(n) - 1)
2683
+ if (key === 'ArrowDown') return Math.min(last, i + 1)
2684
+ if (key === 'ArrowUp') return Math.max(0, i - 1)
2685
+ if (key === 'Home') return 0
2686
+ if (key === 'End') return last
2687
+ return null
2688
+ }
2689
+ const isRowControl = function (t) {
2690
+ if (!t || !t.tagName) return false
2691
+ const tag = String(t.tagName).toLowerCase()
2692
+ if (tag === 'a' || tag === 'button' || tag === 'input' || tag === 'textarea' || tag === 'select') return true
2693
+ if (t.isContentEditable === true) return true
2694
+ return !!(t.closest && t.closest('a,button,input,textarea,select,[contenteditable="true"]'))
2695
+ }
2696
+ const copyLink = function (url) {
2697
+ const text = url || ''
2698
+ const fail = function () { toast('warn', '复制链接失败,请手动复制:' + (text || '—')) }
2699
+ if (typeof navigator === 'undefined' || !navigator.clipboard || typeof navigator.clipboard.writeText !== 'function') {
2700
+ fail(); return
2701
+ }
2702
+ try {
2703
+ navigator.clipboard.writeText(text).then(function () { toast('success', '已复制链接') }).catch(fail)
2704
+ } catch (e) { fail() }
2705
+ }
2706
+ // 离线测试缝:只暴露第六步的纯函数,不改变运行路径
2707
+ window.__rankScanBoardTableTest = { sortableCols: sortableCols, nextSort: nextSort, nextRowIdx: nextRowIdx, normalizeSortPref: normalizeSortPref }
2708
+
2607
2709
  function BoardTab(props) {
2608
2710
  const ov = props.ov
2609
2711
  /**
@@ -2616,9 +2718,15 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2616
2718
  const sites = (ov && ov.sites) || []
2617
2719
  // 收起面板会卸载 BoardTab ⇒ 站/榜选择要持久化;日期/排序按榜各记各的
2618
2720
  const [stSite, setStSite] = React.useState(function () { return sel.get().site })
2721
+ const sortPref = function (board) {
2722
+ const raw = sel.pref(board, 'sort')
2723
+ const v = normalizeSortPref(raw)
2724
+ if (v !== raw) sel.setPref(board, 'sort', v)
2725
+ return v
2726
+ }
2619
2727
  const [bt, setBt] = React.useState(function () { return sel.get().board })
2620
2728
  const [sd, setSd] = React.useState(function () { return sel.pref(sel.get().board, 'date') })
2621
- const [ss, setSs] = React.useState(function () { return sel.pref(sel.get().board, 'sort') })
2729
+ const [ss, setSs] = React.useState(function () { return sortPref(sel.get().board) })
2622
2730
  const [data, setData] = React.useState(null)
2623
2731
  const [err, setErr] = React.useState(null)
2624
2732
  const [pick, setPick] = React.useState(null)
@@ -2641,6 +2749,10 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2641
2749
  // 读取序号:只有最后一次发起的请求允许写界面(防旧响应覆盖)
2642
2750
  const loadSeqRef = React.useRef(0)
2643
2751
  const catSeqRef = React.useRef(0)
2752
+ const listRef = React.useRef(null)
2753
+ const sortJumpRef = React.useRef(false)
2754
+ const pickIdxRef = React.useRef(null)
2755
+ const focusBackRef = React.useRef(null)
2644
2756
  const curSite = stSite || (sites[0] && sites[0].site)
2645
2757
  const curBoards = ((sites.filter(function (s) { return s.site === curSite })[0] || {}).boards) || []
2646
2758
  const curBoard = bt || (curBoards[0] && curBoards[0].boardId)
@@ -2711,7 +2823,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2711
2823
  h('select', { value: value, onChange: function (e) { onChange(e.target.value) }, style: C.input },
2712
2824
  options.map(function (o) { return h('option', { key: o.value, value: o.value }, o.label) })))
2713
2825
  }
2714
- const pickBoard = function (v) { sel.set({ board: v }); setBt(v); setSd(sel.pref(v, 'date')); setSs(sel.pref(v, 'sort')); setPick(null); setDayOpen(false) }
2826
+ const pickBoard = function (v) { sel.set({ board: v }); setBt(v); setSd(sel.pref(v, 'date')); setSs(sortPref(v)); setPick(null); setDayOpen(false) }
2715
2827
  const pickSite = function (v) { sel.set({ site: v, board: null }); setStSite(v); setBt(null); setSd(''); setSs(''); setPick(null); setDayOpen(false) }
2716
2828
  const pickDate = function (v) { setSd(v); sel.setPref(curBoard, 'date', v) }
2717
2829
  /** 「按上架日回看…」是动作项,不是日期值:不改当前选择,只在下面展开输入行 */
@@ -2720,7 +2832,57 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2720
2832
  setDayOpen(false)
2721
2833
  pickDate(v)
2722
2834
  }
2723
- const pickSort = function (v) { setSs(v); sel.setPref(curBoard, 'sort', v) }
2835
+ const pickSort = function (v) {
2836
+ if (v === ss) return
2837
+ setSs(v)
2838
+ sel.setPref(curBoard, 'sort', v)
2839
+ setPick(null) // 换排序 ⇒ 收起详情,避免详情还停在旧行
2840
+ pickIdxRef.current = null
2841
+ sortJumpRef.current = true
2842
+ }
2843
+ const closeDetail = function () {
2844
+ const idx = pickIdxRef.current
2845
+ setPick(null)
2846
+ if (idx != null) focusBackRef.current = idx
2847
+ }
2848
+ const toggleRow = function (r, i) {
2849
+ const opening = !(pick && pick.key === r.key)
2850
+ pickIdxRef.current = i
2851
+ if (!opening) focusBackRef.current = null
2852
+ setPick(opening ? r : null)
2853
+ }
2854
+ const onRowsKeyDown = function (e) {
2855
+ if (!e) return
2856
+ if (isRowControl(e.target)) return
2857
+ const row = e.target && e.target.closest ? e.target.closest('[data-row-idx]') : null
2858
+ if (!row || !e.currentTarget || !e.currentTarget.querySelectorAll) return
2859
+ const rows = e.currentTarget.querySelectorAll('[data-row-idx]')
2860
+ const i = Number(row.getAttribute('data-row-idx'))
2861
+ const next = nextRowIdx(i, e.key, rows.length)
2862
+ if (next == null) return
2863
+ e.preventDefault()
2864
+ const el = rows[next]
2865
+ if (!el) return
2866
+ try { el.focus({ preventScroll: true }) } catch (err) { try { el.focus() } catch (e2) {} }
2867
+ if (el.scrollIntoView) el.scrollIntoView({ block: 'nearest' })
2868
+ }
2869
+ React.useEffect(function () {
2870
+ if (!sortJumpRef.current) return
2871
+ sortJumpRef.current = false
2872
+ const el = listRef.current
2873
+ if (el && el.scrollIntoView) {
2874
+ try { el.scrollIntoView({ block: 'start' }) } catch (e) {}
2875
+ }
2876
+ }, [ss])
2877
+ React.useEffect(function () {
2878
+ if (pick || focusBackRef.current == null) return
2879
+ const idx = focusBackRef.current
2880
+ focusBackRef.current = null
2881
+ const el = listRef.current && listRef.current.querySelector('[data-row-idx="' + idx + '"]')
2882
+ if (!el) return
2883
+ try { el.focus({ preventScroll: true }) } catch (e) { try { el.focus() } catch (e2) {} }
2884
+ if (el.scrollIntoView) el.scrollIntoView({ block: 'nearest' })
2885
+ }, [pick])
2724
2886
  /** 只保存条数(**不采集**);另有一个明确的「保存并扫描本榜」 */
2725
2887
  const saveDepth = function (alsoScan) {
2726
2888
  const n = Math.max(1, Math.min(info.max || 100, Number(depth) || 10))
@@ -2827,6 +2989,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2827
2989
  boardId: curBoard,
2828
2990
  columns: prev.columns || [],
2829
2991
  sortOptions: prev.sortOptions || [],
2992
+ defaultSortKey: (r && r.defaultSortKey) || null,
2830
2993
  rows: (r.rowsAll || []).map(function (x) { return { ...x, delta: null, days: null } }),
2831
2994
  dates: ds,
2832
2995
  dataDate: shown,
@@ -2845,7 +3008,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2845
3008
  }).catch(function (e) { setNote(null); toast('error', '直查失败:' + e) }).then(function () { setBusy(false) })
2846
3009
  }
2847
3010
  // Esc:先关详情卡(面板本身由 Panel 那层关)
2848
- useEscLayer(pick ? function () { setPick(null); return true } : null)
3011
+ useEscLayer(pick ? function () { closeDetail(); return true } : null)
2849
3012
  /** 状态带:一行说清「你在看哪份数据、跟哪天比」 */
2850
3013
  const band = (function () {
2851
3014
  if (!data) return null
@@ -2884,6 +3047,12 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2884
3047
  const dateOptsShown = canDay ? dateOpts.concat([{ value: '__day', label: '按上架日回看…' }]) : dateOpts
2885
3048
  // 减掉正文左右 padding(20)、纵向滚动条与一点余量 ⇒ 表格不会溢出成横向滚动
2886
3049
  const cols = fitColumns(data && data.columns, avail - 48)
3050
+ const defaultSort = (data && data.defaultSortKey && data.defaultSortKey.key)
3051
+ ? data.defaultSortKey
3052
+ : { key: 'rank', dir: 'ascending' }
3053
+ const sortable = sortableCols(cols, sortOpts, defaultSort.key, defaultSort.dir)
3054
+ const sortableMap = {}
3055
+ sortable.forEach(function (c) { sortableMap[c.key] = c.dir })
2887
3056
  const viewDate = (data && (data._queryDate || sd)) || ''
2888
3057
  /* 0.4.2:本榜操作不再进「更多」——扫描/补全在操作条,条数在「本榜设置」,回看在日期行。 */
2889
3058
  /**
@@ -2923,7 +3092,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2923
3092
  */
2924
3093
  const detailCard = function (r) {
2925
3094
  const ex = r.extra || {}
2926
- return h('div', { style: { ...C.detail, marginTop: '4px' } },
3095
+ return h('div', { style: { ...C.detail, marginTop: '4px', boxShadow: 'inset 3px 0 0 ' + T.accent } },
2927
3096
  h('div', { style: { fontWeight: 600 } }, dash(r.title)),
2928
3097
  h('div', { style: C.muted }, '作者 ' + dash(r.author) + ' · 名次 ' + dash(r.rank) + ' · 字数 ' + fmtWords(ex.wordsText || ex.wordsCnt || ex.wordNumber || ex.words)),
2929
3098
  h('div', { style: C.muted }, '更新 ' + fmtTime(ex.lastChapterUpdateTime)),
@@ -2934,10 +3103,10 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2934
3103
  h('div', { style: C.row },
2935
3104
  h(BookmarkStar, { bookKey: bookKeyOf(curBoard, r.key), row: r, boardId: curBoard, dataDate: data && data.dataDate }),
2936
3105
  h(DetailBookmarkEditor, { bookKey: bookKeyOf(curBoard, r.key) }),
2937
- h('button', { className: 'rs-btn', onClick: function (e) { e.stopPropagation(); if (props.openLink) props.openLink(r.url); else window.open(r.url, '_blank', 'noopener,noreferrer') } }, '在 DSH 侧栏浏览器打开'),
3106
+ h('button', { className: 'rs-btn is-primary', onClick: function (e) { e.stopPropagation(); if (props.openLink) props.openLink(r.url); else window.open(r.url, '_blank', 'noopener,noreferrer') } }, '在 DSH 侧栏浏览器打开'),
3107
+ h('button', { className: 'rs-btn', onClick: function (e) { e.stopPropagation(); copyLink(r.url) } }, '复制链接'),
2938
3108
  h('a', { href: r.url || '#', target: '_blank', rel: 'noreferrer', style: { color: 'inherit', padding: '3px 8px' }, onClick: function (e) { e.stopPropagation() } }, '新标签打开'),
2939
- h('button', { className: 'rs-btn', onClick: function (e) { e.stopPropagation(); try { navigator.clipboard.writeText(r.url || '') } catch (err) {} } }, '复制链接'),
2940
- h('button', { className: 'rs-btn', onClick: function (e) { e.stopPropagation(); setPick(null) } }, '关闭')),
3109
+ h('button', { className: 'rs-btn is-ghost', style: { marginLeft: 'auto' }, onClick: function (e) { e.stopPropagation(); closeDetail() } }, '关闭')),
2941
3110
  ex.qidiantuUrl || ex.sourceUrl
2942
3111
  ? h('div', { style: C.row },
2943
3112
  (ex.qidiantuUrl ? h('button', { className: 'rs-btn', onClick: function (e) { e.stopPropagation(); (props.openLink || window.open)(ex.qidiantuUrl) } }, '看起点图原始页') : null),
@@ -2961,11 +3130,17 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2961
3130
  return h('div', {
2962
3131
  key: r.key || ('row' + i),
2963
3132
  tabIndex: 0,
3133
+ 'data-row-idx': i,
3134
+ 'aria-expanded': open ? 'true' : 'false',
2964
3135
  style: { ...C.card, padding: '5px 8px', margin: '5px 0', cursor: 'pointer',
2965
3136
  borderColor: open ? T.border : undefined,
2966
- background: open ? T.subtle : undefined },
2967
- onClick: function () { setPick(open ? null : r) },
2968
- onKeyDown: function (e) { if (e && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); setPick(open ? null : r) } },
3137
+ background: open ? T.subtle : undefined,
3138
+ boxShadow: open ? 'inset 3px 0 0 ' + T.accent : undefined },
3139
+ onClick: function () { toggleRow(r, i) },
3140
+ onKeyDown: function (e) {
3141
+ if (!e || isRowControl(e.target)) return
3142
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleRow(r, i) }
3143
+ },
2969
3144
  },
2970
3145
  h('div', { style: { display: 'flex', alignItems: 'center', gap: '5px', minWidth: 0 } },
2971
3146
  h('span', { style: { ...C.num, ...C.muted, flex: '0 0 auto', minWidth: '16px', textAlign: 'right' } }, dash(r.rank)),
@@ -3043,29 +3218,53 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3043
3218
  note ? h('div', { style: C.muted }, note) : null,
3044
3219
  data && data.rows && data.rows.length
3045
3220
  ? (cards
3046
- ? h('div', null, data.rows.map(function (r, i) {
3221
+ ? h('div', { ref: listRef, onKeyDown: onRowsKeyDown }, data.rows.map(function (r, i) {
3047
3222
  // 卡片行 + 展开时紧跟其后的详情卡(详情别再挂到列表末尾)
3048
3223
  return h('div', { key: 'w' + (r.key || i) }, narrowRow(r, i), isOpen(r) ? detailCard(r) : null)
3049
3224
  }))
3050
- : h('table', { style: C.table },
3051
- h('thead', null, h('tr', null, cols.map(function (c) { return h('th', { key: c.key, style: C.th, title: c.note || '' }, c.label) }))),
3052
- h('tbody', null, data.rows.flatMap(function (r, i) {
3225
+ : h('table', { ref: listRef, style: C.table },
3226
+ h('thead', null, h('tr', null, cols.map(function (c) {
3227
+ const dir = sortableMap[c.key]
3228
+ const active = (ss || defaultSort.key) === c.key
3229
+ const shownDir = active ? (ss ? dir : defaultSort.dir) : dir
3230
+ return h('th', {
3231
+ key: c.key, style: C.th, title: c.note || '',
3232
+ 'aria-sort': active ? shownDir : undefined,
3233
+ }, dir
3234
+ ? h('button', {
3235
+ className: 'rs-th-sort',
3236
+ title: active && !ss ? '当前为默认排序' : active ? '取消按 ' + c.label + ' 排序' : '按 ' + c.label + ' 排序',
3237
+ onClick: function (e) { e.stopPropagation(); pickSort(nextSort(ss, c.key, defaultSort.key)) },
3238
+ }, c.label, h('span', { className: 'rs-sort-arrow' + (active ? ' is-on' : ''), 'aria-hidden': 'true' }, shownDir === 'ascending' ? '↑' : '↓'))
3239
+ : c.label)
3240
+ }))),
3241
+ h('tbody', { onKeyDown: onRowsKeyDown }, data.rows.flatMap(function (r, i) {
3242
+ const open = isOpen(r)
3053
3243
  const tr = h('tr', {
3054
3244
  key: r.key || i,
3055
3245
  tabIndex: 0,
3056
- style: { cursor: 'pointer' },
3057
- onClick: function () { setPick(isOpen(r) ? null : r) },
3058
- onKeyDown: function (e) { if (e && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); setPick(isOpen(r) ? null : r) } },
3059
- }, cols.map(function (c) {
3060
- return h('td', { key: c.key, style: isNumCol(c.key) ? { ...C.td, ...C.num } : C.td }, cell(rowCellProps(r, c), r))
3246
+ 'data-row-idx': i,
3247
+ 'aria-expanded': open ? 'true' : 'false',
3248
+ style: { cursor: 'pointer', background: open ? T.subtle : undefined },
3249
+ onClick: function () { toggleRow(r, i) },
3250
+ onKeyDown: function (e) {
3251
+ if (!e || isRowControl(e.target)) return
3252
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleRow(r, i) }
3253
+ },
3254
+ }, cols.map(function (c, ci) {
3255
+ const baseStyle = isNumCol(c.key) ? { ...C.td, ...C.num } : C.td
3256
+ const style = open && ci === 0 ? { ...baseStyle, boxShadow: 'inset 3px 0 0 ' + T.accent } : baseStyle
3257
+ return h('td', { key: c.key, style }, cell(rowCellProps(r, c), r))
3061
3258
  }))
3062
3259
  // 详情卡作为紧跟那一行的一行(colSpan 占满),点哪一行就在哪一行下面展开
3063
- return isOpen(r)
3260
+ return open
3064
3261
  ? [tr, h('tr', { key: 'd' + (r.key || i) }, h('td', { colSpan: Math.max(1, cols.length), style: { padding: '0 0 4px' } }, detailCard(r)))]
3065
3262
  : [tr]
3066
3263
  }))))
3067
3264
  : h('div', { style: C.muted }, data ? dash(data.note || '没有条目') : '加载中…'),
3068
- h('div', { style: { ...C.muted, marginTop: '6px' } }, '列随榜变化:该站没有的字段整列不出现;有字段但这条没抓到显示「—」(批次榜不出「变化」列)。面板变窄时列会按宽度自动收起(先收作者/分类/字数这类次级列,名次/书名与该榜主指标一直在),再窄就换成卡片行;点行看详情。'))
3265
+ h('details', { style: { ...C.muted, marginTop: '6px' } },
3266
+ h('summary', { style: { cursor: 'pointer' } }, '列说明'),
3267
+ h('div', { style: { marginTop: '3px' } }, '列随榜变化:该站没有的字段整列不出现;有字段但这条没抓到显示「—」(批次榜不出「变化」列)。面板变窄时列会按宽度自动收起(先收作者/分类/字数这类次级列,名次/书名与该榜主指标一直在),再窄就换成卡片行;点行看详情。')))
3069
3268
  }
3070
3269
 
3071
3270
  /**
@@ -3103,6 +3302,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3103
3302
  * · 无障碍名由注册项的 label 提供(宿主做 aria-label + tooltip),不是内部 id。
3104
3303
  * 开关浮窗的入口在下方的「薄 main 面板」里(Q29)。
3105
3304
  */
3305
+ /* ---- parts/80-panel.js ---- */
3306
+ /**
3307
+ * 80-panel.js:侧栏入口图标与 Panel 外壳(页签、轮询、尺寸、Toast 挂载)。依赖前面全部页签。不要放 apply。
3308
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
3309
+ */
3106
3310
  function SidebarEntryIcon(props) {
3107
3311
  const size = Number(props && props.size) || 16
3108
3312
  const active = !!(props && props.active)
@@ -3358,6 +3562,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3358
3562
  * 之前只认 ①,行内/详情卡传进来的是 (url) ⇒ url 形参恒 undefined ⇒ **静默 return,什么也不发生**,
3359
3563
  * 于是「看起点图原始页」点了没反应(使用方 2026-10-15 反馈的就是这个)。
3360
3564
  */
3565
+ /* ---- parts/90-tail.js ---- */
3566
+ /**
3567
+ * 90-tail.js:openLink/diagLink、inject、apply 与 factory 返回值/闭合括号。依赖全部。不要放组件。
3568
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
3569
+ */
3361
3570
  function openLink(ctx, url) {
3362
3571
  if (typeof ctx === 'string' && url === undefined) { url = ctx; ctx = null }
3363
3572
  if (!url) return
package/lib/index.js CHANGED
@@ -21,7 +21,7 @@ import { FANQIE_MALE } from './sites/fanqie.js';
21
21
  import { CATEGORIES as QIDIAN_CATEGORIES } from './sites/qidian-mobile.js';
22
22
  import { deriveFanqieViews } from './scan/derive.js';
23
23
  import { decodePua, hasPua, learnPair, loadFontMap, saveFontMap } from './scan/fontmap.js';
24
- import { applyColumnPolicy, batchKeyOf, batchKindOf, batchLabelOf, boardMeta, columnsFor, compareDesc, defaultSortFor, enrichAttemptPolicy, enrichMissingCount, groupBySite, groupChanges, isBatchBoard, isEnrichableBoard, saleRangeOf, shouldShowDays, usesRankDelta, withFanqieCat } from './scan/view.js';
24
+ import { applyColumnPolicy, batchKeyOf, batchKindOf, batchLabelOf, boardMeta, columnsFor, compareDesc, defaultSortFor, defaultSortKeyFor, enrichAttemptPolicy, enrichMissingCount, groupBySite, groupChanges, isBatchBoard, isEnrichableBoard, saleRangeOf, shouldShowDays, usesRankDelta, withFanqieCat } from './scan/view.js';
25
25
  import { BookmarkService, BookmarkStore } from './scan/bookmark.js';
26
26
  import { parseBookInput } from './scan/bookmark-parse.js';
27
27
  import { decodeIfPua } from './scan/fontmap.js';
@@ -1777,7 +1777,7 @@ export function apply(ctx, config) {
1777
1777
  ];
1778
1778
  }
1779
1779
  const main = mainLabelOf(boardId, meta);
1780
- const opts = [{ value: '', label: '默认(名次)' }, { value: 'rank', label: '名次' }];
1780
+ const opts = [{ value: '', label: '默认(名次)' }];
1781
1781
  // 列名口径:番茄主指标列叫 read(不是 value),排序值必须对上列 key 才不会被客户端过滤掉
1782
1782
  const mainKey = meta.site === 'fanqie' && !boardId.startsWith('fanqie.derived.') ? 'read' : 'value';
1783
1783
  if (meta.metric === 'value')
@@ -1793,7 +1793,7 @@ export function apply(ctx, config) {
1793
1793
  // ★ 兜底过滤(2026-10-15):排序项必须对应**该榜真实存在的列**,
1794
1794
  // 否则列被口径改掉后(比如三江去掉「已结算天数」),下拉里还残留一个按不存在字段排的项。
1795
1795
  const keys = new Set(applyColumnPolicy(columnsFor(meta, { hasBaseline: flags.hasHistory, hasHistory: flags.hasHistory }), boardId).map((c) => c.key));
1796
- return opts.filter((o) => !o.value || o.value === 'rank' || keys.has(o.value));
1796
+ return opts.filter((o) => !o.value || keys.has(o.value));
1797
1797
  }
1798
1798
  /**
1799
1799
  * ★ 2026-10-25(批次榜):把「数据日期」折成「批」。
@@ -1837,8 +1837,10 @@ export function apply(ctx, config) {
1837
1837
  return out;
1838
1838
  }
1839
1839
  async function panelBoard(boardId, dateArg, sort, limit = 0) {
1840
+ const wantedSort = sort === 'rank' ? undefined : sort;
1840
1841
  const { st, dates, latest } = panelCtx();
1841
1842
  const meta = boardMeta(boardId);
1843
+ const defaultSortKey = defaultSortKeyFor(boardId);
1842
1844
  const store = new FileStore(root);
1843
1845
  /**
1844
1846
  * ★ 日期下拉按**该榜自己有快照的日期**过滤(2026-10-15 使用反馈):
@@ -1865,7 +1867,7 @@ export function apply(ctx, config) {
1865
1867
  // 使用者 2026-10-15 点名起点图不要这一列 ⇒ 改成按榜查精简索引里有没有它更早的记录。
1866
1868
  if (!latest) {
1867
1869
  const colsNone = applyColumnPolicy(columnsFor(meta, { hasBaseline: false, hasHistory: false }), boardId);
1868
- return { boardId, meta, columns: colsNone, dataDate: null, dates: [], rows: [], note: '还没有任何快照:先点「立刻扫一次」' };
1870
+ return { boardId, meta, columns: colsNone, dataDate: null, dates: [], rows: [], defaultSortKey, note: '还没有任何快照:先点「立刻扫一次」' };
1869
1871
  }
1870
1872
  // 到这里 latest 一定非空 ⇒ 把日期收窄成非空的本地量(TS 不会因为 latest 非空就收窄 useDate)
1871
1873
  const date = useDate;
@@ -1893,13 +1895,14 @@ export function apply(ctx, config) {
1893
1895
  let rows = (v ? v.rows : []).map((r) => ({ ...r, days: r.extra && r.extra.inPoolDays != null ? r.extra.inPoolDays : null }));
1894
1896
  // ★ 派生榜必须**自己**应用排序(2026-10-15 发现「按在读排序没反应」):
1895
1897
  // 这个分支 return 在通用排序代码**之前**,所以 sort 参数到这里就丢了。
1896
- const derivedSort = sort || defaultSortFor(boardId);
1898
+ const derivedSort = wantedSort || defaultSortFor(boardId);
1897
1899
  if (derivedSort)
1898
1900
  rows = rows.slice().sort((a, b) => compareDesc(num(sortVal(a, derivedSort)), num(sortVal(b, derivedSort))));
1899
1901
  return {
1900
1902
  boardId,
1901
1903
  meta: { ...meta, mainLabel: mainLabelOf(boardId, meta) },
1902
1904
  columns,
1905
+ defaultSortKey,
1903
1906
  sortOptions: sortOptionsFor(boardId, meta, { hasHistory }),
1904
1907
  depth: (st.depths || {})[boardId] ?? 30,
1905
1908
  dataDate: latest,
@@ -1926,7 +1929,7 @@ export function apply(ctx, config) {
1926
1929
  }
1927
1930
  }
1928
1931
  if (!snap)
1929
- return { boardId, meta, columns, dataDate: useDate, dates: shownDates, rows: [], note: '该榜在这天没有快照(也没找到更早的可用快照)' };
1932
+ return { boardId, meta, columns, dataDate: useDate, dates: shownDates, rows: [], defaultSortKey, note: '该榜在这天没有快照(也没找到更早的可用快照)' };
1930
1933
  const effDate = fallbackFrom || date;
1931
1934
  /**
1932
1935
  * ★ 2026-10-25(批次榜):这一屏属于哪一批。面板据此把「数据日期 / 对比 YYYY-MM-DD」
@@ -1965,6 +1968,7 @@ export function apply(ctx, config) {
1965
1968
  return {
1966
1969
  boardId,
1967
1970
  meta: { ...meta, mainLabel: mainLabelOf(boardId, meta) },
1971
+ defaultSortKey,
1968
1972
  sortOptions: sortOptionsFor(boardId, meta, { hasHistory }),
1969
1973
  depth: (st.depths || {})[boardId] ?? (meta.site === 'fanqie' ? 30 : 10),
1970
1974
  columns,
@@ -2187,7 +2191,7 @@ export function apply(ctx, config) {
2187
2191
  // ★ 排序一律**倒序**(使用者 2026-10-15:按字数/收藏/首订排序要「最大的在前」):
2188
2192
  // num() 把缺失值统一成 +Infinity ⇒ 倒序时缺失值会被排到最后(不是最前),这正合口径。
2189
2193
  // ★ 该榜有自己的「默认排序」时,未显式选排序也按它排(使用者 2026-10-15:三江默认按期初收藏)
2190
- const effSort = sort || defaultSortFor(boardId);
2194
+ const effSort = wantedSort || defaultSortFor(boardId);
2191
2195
  if (effSort)
2192
2196
  rows = rows.slice().sort((a, b) => compareDesc(num(sortVal(a, effSort)), num(sortVal(b, effSort))));
2193
2197
  if (limit > 0)
@@ -2226,6 +2230,7 @@ export function apply(ctx, config) {
2226
2230
  return {
2227
2231
  boardId,
2228
2232
  meta: { ...meta, mainLabel: mainLabelOf(boardId, meta) },
2233
+ defaultSortKey,
2229
2234
  sortOptions: sortOptionsFor(boardId, meta, { hasHistory }),
2230
2235
  depth: (st.depths || {})[boardId] ?? (meta.site === 'fanqie' ? 30 : 10),
2231
2236
  columns,
@@ -3701,6 +3706,7 @@ export function apply(ctx, config) {
3701
3706
  }
3702
3707
  return send(200, {
3703
3708
  ok: true, boardId, date, saved: !!body.save, contentDate: verdict.contentDate, expected: verdict.expected,
3709
+ defaultSortKey: defaultSortKeyFor(boardId),
3704
3710
  rowsAll: res.rows,
3705
3711
  count: res.rows.length,
3706
3712
  note: (body.save ? '已抓取并存入本地快照' : '直查站点该日期(未落盘)') + (verdict.contentDate ? ';内容日期 ' + verdict.contentDate : ''),