dsh-half-page 0.4.43 → 0.4.48

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/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # 更新记录
2
+
3
+ ## 0.4.48
4
+
5
+ 这一版三件事:**一本书可以被几个读者分开读**、**书房时间改成「隔多久叫一次」**、**备份/恢复/检查更新真正能用了**。
6
+
7
+ ### 一本书,几个读者,各读各的
8
+
9
+ - 「读者」就是一条会话。每条会话各有自己的「读到哪」,谁都不会踩到谁。
10
+ - 书上另记一个「全机读得最远」——面板顶部显示「最远:第 92 章 · 鹿野(主对话)」,一眼看见别人读到哪了。
11
+ - 新会话第一次读一本别人读过的书,默认接着**全机最远**的地方往下;想从头读、想回看某章,传 `chapter` 或 `from: "start"`。
12
+ - 读后感仍然是一个文件,靠署名分开。设置页里可以按署名筛,面板每条下面会标出是谁写的。
13
+ - 面板:读者下拉只列真读过的会话;点书架里的书名只换你想看的那本,**不改变鱼在读哪本**——读哪本由它自己决定,只有你明确说「你去读某一本」才按你说的读。
14
+
15
+ ### 书房时间:隔多久叫一次,一天最多几次
16
+
17
+ - 原来的「每周/每天 + 次数」跟时段互相抵消,一小时窗口里写「每天 5 次」实际只会响一次,是个死字段。
18
+ - 现在每条书房时间是:**时段 + 隔多久叫一次 + 这段时间里最多几次**,例如「00:00–23:59,每 120 分叫一次,最多 12 次」。
19
+ - 到点只投一句「书房时间到了。读不读随你。」,不替你决定读不读,也不会自己去调 `reading_next`。
20
+ - 删掉了「今天已经读过就不叫」这条——刚读完几章、回完一句话就一整天哑掉,不对。
21
+ - 支持多条书房时间,各自绑一条会话,各算各的计数,跨零点自动归零。
22
+
23
+ ### 备份 / 恢复 / 检查更新
24
+
25
+ - 「备份全部数据」把读后感全文 + 阅读进度写成一个 json 存到 `~/.dsh/reading/backups/`,然后在资源管理器里选中它,你自己挪到哪都行。
26
+ - 「恢复全部数据」选那个 json 就恢复;恢复前旧文件会另存一份 `*bak-restore-*`,后悔能找回来。
27
+ - 设置页底部有「检测更新」,直接说一句「已是最新版 0.4.48」或者「发现新版本 X,点『复制更新命令』去终端里跑」。
28
+
29
+ ### 顺手修的
30
+
31
+ - 面板在 iframe 里,`<a download>` 和 `<input type=file>` 都会被浏览器拦,所以导出/导入全部改成宿主侧落盘。
32
+ - 三条路由以前被塞进同一个注册数组,DSH 只注册第一个,导致「书房时间存不下:未知」——已拆成各自独立注册。
33
+ - 版本号现在稳定显示在面板上(之前取包版本的作用域错了,一直空着)。
package/README.md CHANGED
@@ -91,26 +91,27 @@ dsh plugin add dsh-half-page
91
91
 
92
92
  不带书名、不带进度、不提醒写批注,也**不会**自动调 `reading_next`——读不读是它自己下一步要说的话。
93
93
 
94
- 设置页里:开关、时段(`22:00` 至 `23:00`,起止写反就表示跨夜)、叫的频率(「每周」或「每天」点一下切换,1–7 次,默认每周 3 次),以及在哪条会话里叫(默认「最近活跃的会话」,也可以指定某一条)。
94
+ 设置页里:开关、时段(`22:00` 至 `23:00`,起止写反就表示跨夜)、叫的频率(`15 / 30 / 60 / 120 分钟`,是**最小间隔**,不是把时段均分)和「这段里一天最多叫几次」,以及在哪条会话里叫(默认「最近活跃的会话」,也可以指定某一条)。
95
95
 
96
96
  > 同时装了「鱼的心跳」的话,建议这条别勾——两边各叫各的,不会互相避让。
97
97
 
98
98
  全部满足才投,一条不满足就静默跳过:
99
99
 
100
100
  - 开关为真、时段合法、当前在时段内(本地时间)
101
- - 今天还没叫过、本周次数没用完(周一凌晨归零)
101
+ - 距上次叫满一个「频次」间隔,且今天还没到「最多几次」的上限(跨天归零)
102
102
  - 这个会话最后一条用户消息已过 5 分钟,且已经回过
103
103
  - 10 分钟内这条会话没有别的 notice(跟心跳避让,不一次叫两声)
104
- - 今天还没读过(任一书的 `lastReadAt` 不是今天)
105
104
 
106
- 计数落在 `state.json` 的 `study: { lastAt, week, weekCount, day, dayCount }`;重启后还在。
105
+ **「今天读过了」不再拦它**:读得正起劲时它照样会按频次再叫一声,不理就行——所以次数靠「上限」管,不靠「读过没读过」。
106
+
107
+ 计数落在 `state.json` 的 `study.slots[].{lastAt, day, dayCount}`;重启后还在。
107
108
 
108
109
  ## License
109
110
 
110
111
  MIT
111
-
112
- ### 读哪一本,由鱼自己决定
113
-
114
- 面板顶部那个「当前这本」只是**你想看哪本**,它不会改变工具默认读哪本——只有你明确说「你去读某一本」,它才按你说的读。其余时候归读者自己的进度:
115
-
112
+
113
+ ### 读哪一本,由鱼自己决定
114
+
115
+ 面板顶部那个「当前这本」只是**你想看哪本**,它不会改变工具默认读哪本——只有你明确说「你去读某一本」,它才按你说的读。其余时候归读者自己的进度:
116
+
116
117
  这么定是因为反过来会把权力放错地方:面板是你看书的地方,不是给鱼派书的地方。
package/client.js CHANGED
@@ -48,28 +48,28 @@ window.__ModuleLoader__.load({
48
48
  }
49
49
  const copy = (t) => { try { navigator.clipboard.writeText(t) } catch {} }
50
50
 
51
- // 面板在 iframe 里,浏览器不让直接下载/选文件;备份交给宿主写盘,恢复给一个路径让宿主读
52
- // 备份:由宿主弹「另存为」,用户自己选位置
53
- async function backupAll() {
54
- setBusy(true)
55
- setMsg('正在打包…', 'bak')
56
- try {
57
- const r = await getJson('/dsh-reading.backupFile', { method: 'POST' })
58
- if (r && r.ok) {
59
- setLastBackup(r.path)
60
- setMsg('已备份到 ' + r.path, 'bak')
61
- try {
62
- await getJson('/dsh-reading.reveal', {
63
- method: 'POST',
64
- headers: { 'content-type': 'application/json' },
65
- body: JSON.stringify({ path: r.path }),
66
- })
67
- } catch {}
68
- } else setMsg('备份失败:' + ((r && r.error) || '未知'), 'bak')
69
- } catch (e) {
70
- setMsg('备份失败:' + String(e), 'bak')
71
- } finally { setBusy(false) }
72
- }
51
+ // 面板在 iframe 里,浏览器不让直接下载/选文件;备份交给宿主写盘,恢复给一个路径让宿主读
52
+ // 备份:由宿主弹「另存为」,用户自己选位置
53
+ async function backupAll() {
54
+ setBusy(true)
55
+ setMsg('正在打包…', 'bak')
56
+ try {
57
+ const r = await getJson('/dsh-reading.backupFile', { method: 'POST' })
58
+ if (r && r.ok) {
59
+ setLastBackup(r.path)
60
+ setMsg('已备份到 ' + r.path, 'bak')
61
+ try {
62
+ await getJson('/dsh-reading.reveal', {
63
+ method: 'POST',
64
+ headers: { 'content-type': 'application/json' },
65
+ body: JSON.stringify({ path: r.path }),
66
+ })
67
+ } catch {}
68
+ } else setMsg('备份失败:' + ((r && r.error) || '未知'), 'bak')
69
+ } catch (e) {
70
+ setMsg('备份失败:' + String(e), 'bak')
71
+ } finally { setBusy(false) }
72
+ }
73
73
  async function reveal(p) {
74
74
  try {
75
75
  const r = await getJson('/dsh-reading.reveal', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: p }) })
@@ -77,47 +77,47 @@ window.__ModuleLoader__.load({
77
77
  } catch (e) { setMsg('打不开文件夹:' + String((e && e.message) || e), 'bak') }
78
78
  }
79
79
 
80
- async function checkUpd() {
81
- setBusy(true)
82
- try {
83
- const r = await getJson('/dsh-reading.update')
84
- if (r && r.ok) {
85
- const d = new Date()
86
- const pad = (n) => String(n).padStart(2, '0')
87
- setUpd({ ...r, at: pad(d.getHours()) + ':' + pad(d.getMinutes()) })
88
- setMsg(r.outdated ? ('发现新版本 ' + r.latest + ':可以点「复制更新命令」,在终端里跑') : (r.latest ? ('已是最新版 ' + r.current + ',不用更新') : '查不到 npm(可能离线),稍后再试'), 'upd')
89
- } else setMsg('检测失败:' + ((r && r.error) || '未知'), 'upd')
90
- } catch (e) { setMsg('检测失败:' + String((e && e.message) || e), 'upd') } finally { setBusy(false) }
91
- }
92
-
93
- // 恢复:由宿主弹「打开」,选完直接恢复
94
- async function restoreFromPath() {
95
- setBusy(true)
96
- setMsg('正在读取备份…', 'bak')
97
- try {
98
- let path = (restorePath || '').trim()
99
- if (!path) {
100
- const pick = await getJson('/dsh-reading.pickFile', { method: 'POST' })
101
- if (!pick || !pick.ok) {
102
- setMsg((pick && pick.cancelled) ? '取消了,没恢复' : ('没选到文件:' + ((pick && pick.error) || '窗口没起来,可以直接把路径填在下面')), 'bak')
103
- return
104
- }
105
- path = pick.path
106
- setRestorePath(path)
107
- }
108
- const f = await getJson('/dsh-reading.readFile?path=' + encodeURIComponent(path))
109
- if (!f || !f.ok) { setMsg('读不到那个文件:' + ((f && f.error) || '未知'), 'bak'); return }
110
- const r = await getJson('/dsh-reading.restore', {
111
- method: 'POST',
112
- headers: { 'content-type': 'application/json' },
113
- body: JSON.stringify({ json: f.text }),
114
- })
115
- if (r && r.ok) { setMsg('已恢复:' + (r.books || 0) + ' 本 · ' + (r.chapters || 0) + ' 段读后感', 'bak'); await load() }
116
- else setMsg('恢复失败:' + ((r && r.error) || '未知'), 'bak')
117
- } catch (e) {
118
- setMsg('恢复失败:' + String(e), 'bak')
119
- } finally { setBusy(false) }
120
- }
80
+ async function checkUpd() {
81
+ setBusy(true)
82
+ try {
83
+ const r = await getJson('/dsh-reading.update')
84
+ if (r && r.ok) {
85
+ const d = new Date()
86
+ const pad = (n) => String(n).padStart(2, '0')
87
+ setUpd({ ...r, at: pad(d.getHours()) + ':' + pad(d.getMinutes()) })
88
+ setMsg(r.outdated ? ('发现新版本 ' + r.latest + ':可以点「复制更新命令」,在终端里跑') : (r.latest ? ('已是最新版 ' + r.current + ',不用更新') : '查不到 npm(可能离线),稍后再试'), 'upd')
89
+ } else setMsg('检测失败:' + ((r && r.error) || '未知'), 'upd')
90
+ } catch (e) { setMsg('检测失败:' + String((e && e.message) || e), 'upd') } finally { setBusy(false) }
91
+ }
92
+
93
+ // 恢复:由宿主弹「打开」,选完直接恢复
94
+ async function restoreFromPath() {
95
+ setBusy(true)
96
+ setMsg('正在读取备份…', 'bak')
97
+ try {
98
+ let path = (restorePath || '').trim()
99
+ if (!path) {
100
+ const pick = await getJson('/dsh-reading.pickFile', { method: 'POST' })
101
+ if (!pick || !pick.ok) {
102
+ setMsg((pick && pick.cancelled) ? '取消了,没恢复' : ('没选到文件:' + ((pick && pick.error) || '窗口没起来,可以直接把路径填在下面')), 'bak')
103
+ return
104
+ }
105
+ path = pick.path
106
+ setRestorePath(path)
107
+ }
108
+ const f = await getJson('/dsh-reading.readFile?path=' + encodeURIComponent(path))
109
+ if (!f || !f.ok) { setMsg('读不到那个文件:' + ((f && f.error) || '未知'), 'bak'); return }
110
+ const r = await getJson('/dsh-reading.restore', {
111
+ method: 'POST',
112
+ headers: { 'content-type': 'application/json' },
113
+ body: JSON.stringify({ json: f.text }),
114
+ })
115
+ if (r && r.ok) { setMsg('已恢复:' + (r.books || 0) + ' 本 · ' + (r.chapters || 0) + ' 段读后感', 'bak'); await load() }
116
+ else setMsg('恢复失败:' + ((r && r.error) || '未知'), 'bak')
117
+ } catch (e) {
118
+ setMsg('恢复失败:' + String(e), 'bak')
119
+ } finally { setBusy(false) }
120
+ }
121
121
  async function getJson(url, opt) {
122
122
  const r = await fetch(url, opt)
123
123
  return r.json()
@@ -346,7 +346,7 @@ window.__ModuleLoader__.load({
346
346
  }, [state])
347
347
  // 整条列表一起存:新增/删/改时段都走这里
348
348
  const saveSlots = async (next) => {
349
- const body = { slots: (next || []).map((s) => ({ id: s.id, enabled: s.enabled === true, from: s.from, to: s.to, mode: s.mode, per: s.per, session: s.session })) }
349
+ const body = { slots: (next || []).map((s) => ({ id: s.id, enabled: s.enabled === true, from: s.from, to: s.to, mode: s.mode, per: s.per, everyMinutes: s.everyMinutes, dailyBudget: s.dailyBudget, session: s.session })) }
350
350
  const r = await fetch('/dsh-reading.study', {
351
351
  method: 'POST',
352
352
  headers: { 'content-type': 'application/json' },
@@ -722,7 +722,7 @@ window.__ModuleLoader__.load({
722
722
  style: { ...S.btn, fontSize: 11, padding: '2px 8px' },
723
723
  title: '可以有多条:不同时段、不同频率、叫进不同会话',
724
724
  onClick: () => {
725
- const next = slots.concat([{ id: 'slot-' + Date.now().toString(36), enabled: false, from: '22:00', to: '23:00', mode: 'day', per: 1, session: '' }])
725
+ const next = slots.concat([{ id: 'slot-' + Date.now().toString(36), enabled: false, from: '22:00', to: '23:00', everyMinutes: 30, dailyBudget: 2, session: '' }])
726
726
  setSlots(next); saveSlots(next)
727
727
  },
728
728
  }, '新增书房时间'),
@@ -751,24 +751,25 @@ window.__ModuleLoader__.load({
751
751
  onChange: (e) => { const next = slots.slice(); next[i] = { ...s, to: e.target.value }; setSlots(next) },
752
752
  onBlur: () => saveSlots(slots),
753
753
  }),
754
- h('button', {
755
- style: S.btn,
756
- title: '点一下在「每周 / 每天」之间切换',
757
- onClick: () => {
758
- const next = slots.slice()
759
- const mode = s.mode === 'day' ? 'week' : 'day'
760
- next[i] = { ...s, mode, per: mode === 'day' ? 1 : 3 }
761
- setSlots(next); saveSlots(next)
762
- },
763
- }, s.mode === 'day' ? '每天' : '每周'),
754
+ h('div', { style: S.dim }, '这段时间内每'),
755
+ h('select', {
756
+ style: { ...S.input, width: 80 },
757
+ value: s.everyMinutes || 30,
758
+ title: '隔多久叫一次(最小间隔)',
759
+ onChange: (e) => { const next = slots.slice(); next[i] = { ...s, everyMinutes: Number(e.target.value) || 30 }; setSlots(next); saveSlots(next) },
760
+ },
761
+ [15, 30, 60, 120].map((m) => h('option', { key: m, value: m }, m + ' 分')),
762
+ ),
763
+ h('div', { style: S.dim }, '叫一次,最多'),
764
764
  h('input', {
765
765
  style: { ...S.input, width: 56 },
766
- type: 'number', min: 1, max: 7,
767
- value: s.per || 1,
768
- onChange: (e) => { const next = slots.slice(); next[i] = { ...s, per: Math.min(7, Math.max(1, Number(e.target.value) || 1)) }; setSlots(next) },
766
+ type: 'number', min: 1, max: 24,
767
+ value: s.dailyBudget || 2,
768
+ title: '这段里一天最多叫几次',
769
+ onChange: (e) => { const next = slots.slice(); next[i] = { ...s, dailyBudget: Math.min(24, Math.max(1, Number(e.target.value) || 1)) }; setSlots(next) },
769
770
  onBlur: () => saveSlots(slots),
770
771
  }),
771
- h('div', { style: S.dim }, '次'),
772
+ h('div', { style: S.dim }, '次/天'),
772
773
  h('select', {
773
774
  style: { ...S.input, width: 160 },
774
775
  value: s.session || '',
@@ -871,77 +872,77 @@ window.__ModuleLoader__.load({
871
872
  ),
872
873
  h('div', { style: S.card },
873
874
  h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '备份 / 恢复'),
874
- h('div', { style: S.row },
875
- h('button', { style: S.btn, onClick: async () => {
876
- setBusy(true)
877
- setMsg('正在打包…', 'bak')
878
- try {
879
- const r = await fetch('/dsh-reading.backupFile', { method: 'POST' }).then((x) => x.json())
880
- if (r && r.ok) {
881
- setLastBackup(r.path)
882
- setMsg('已备份到 ' + r.path, 'bak')
883
- fetch('/dsh-reading.reveal', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: r.path }) }).catch(() => {})
884
- } else setMsg('备份失败:' + ((r && r.error) || '未知'), 'bak')
885
- } catch (e) {
886
- setMsg('备份失败:' + String(e), 'bak')
887
- } finally { setBusy(false) }
875
+ h('div', { style: S.row },
876
+ h('button', { style: S.btn, onClick: async () => {
877
+ setBusy(true)
878
+ setMsg('正在打包…', 'bak')
879
+ try {
880
+ const r = await fetch('/dsh-reading.backupFile', { method: 'POST' }).then((x) => x.json())
881
+ if (r && r.ok) {
882
+ setLastBackup(r.path)
883
+ setMsg('已备份到 ' + r.path, 'bak')
884
+ fetch('/dsh-reading.reveal', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: r.path }) }).catch(() => {})
885
+ } else setMsg('备份失败:' + ((r && r.error) || '未知'), 'bak')
886
+ } catch (e) {
887
+ setMsg('备份失败:' + String(e), 'bak')
888
+ } finally { setBusy(false) }
888
889
  } }, '备份全部数据'),
889
- h('button', { style: S.btn, onClick: () => { if (!lastBackup) { setMsg('先点一次备份', 'bak'); return } reveal(lastBackup) } }, '在文件夹里打开'),
890
- ),
891
- h('div', { style: { ...S.row, marginTop: 6 } },
892
- h('button', { style: S.btn, onClick: async () => {
893
- setBusy(true)
894
- setMsg('正在读取备份…', 'bak')
895
- try {
896
- let path = (restorePath || '').trim()
897
- if (!path) {
898
- const pick = await fetch('/dsh-reading.pickFile', { method: 'POST' }).then((x) => x.json()).catch(() => null)
899
- if (pick && pick.ok && pick.path) { path = pick.path; setRestorePath(path) }
900
- }
901
- if (!path) { setMsg('先点「选择备份文件」,或把完整路径填在下面的框里', 'bak'); return }
902
- const f = await fetch('/dsh-reading.readFile?path=' + encodeURIComponent(path)).then((x) => x.json())
903
- if (!f || !f.ok) { setMsg('读不到那个文件:' + ((f && f.error) || '未知'), 'bak'); return }
904
- const r = await fetch('/dsh-reading.restore', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ json: f.text }) }).then((x) => x.json())
905
- if (r && r.ok) { setMsg('已恢复:' + (r.books || 0) + ' 本 · ' + (r.chapters || 0) + ' 段读后感', 'bak'); await load() }
906
- else setMsg('恢复失败:' + ((r && r.error) || '未知'), 'bak')
907
- } catch (e) {
908
- setMsg('恢复失败:' + String(e), 'bak')
909
- } finally { setBusy(false) }
910
- } }, '恢复全部数据'),
890
+ h('button', { style: S.btn, onClick: () => { if (!lastBackup) { setMsg('先点一次备份', 'bak'); return } reveal(lastBackup) } }, '在文件夹里打开'),
891
+ ),
892
+ h('div', { style: { ...S.row, marginTop: 6 } },
893
+ h('button', { style: S.btn, onClick: async () => {
894
+ setBusy(true)
895
+ setMsg('正在读取备份…', 'bak')
896
+ try {
897
+ let path = (restorePath || '').trim()
898
+ if (!path) {
899
+ const pick = await fetch('/dsh-reading.pickFile', { method: 'POST' }).then((x) => x.json()).catch(() => null)
900
+ if (pick && pick.ok && pick.path) { path = pick.path; setRestorePath(path) }
901
+ }
902
+ if (!path) { setMsg('先点「选择备份文件」,或把完整路径填在下面的框里', 'bak'); return }
903
+ const f = await fetch('/dsh-reading.readFile?path=' + encodeURIComponent(path)).then((x) => x.json())
904
+ if (!f || !f.ok) { setMsg('读不到那个文件:' + ((f && f.error) || '未知'), 'bak'); return }
905
+ const r = await fetch('/dsh-reading.restore', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ json: f.text }) }).then((x) => x.json())
906
+ if (r && r.ok) { setMsg('已恢复:' + (r.books || 0) + ' 本 · ' + (r.chapters || 0) + ' 段读后感', 'bak'); await load() }
907
+ else setMsg('恢复失败:' + ((r && r.error) || '未知'), 'bak')
908
+ } catch (e) {
909
+ setMsg('恢复失败:' + String(e), 'bak')
910
+ } finally { setBusy(false) }
911
+ } }, '恢复全部数据'),
911
912
  ), msgAt === 'bak' ? h('div', { style: { ...S.dim, color: C.ok, marginTop: 4 } }, msg) : null,
912
913
  h('div', { style: { ...S.dim, marginTop: 6 } }, '备份 = 读后感全文 + 阅读进度,存成一个 .json 文件;恢复时在弹出的窗口里选那个文件。恢复前旧文件会存成 *bak-restore-*。'),
913
914
  h('div', { style: { ...S.dim, marginTop: 4 } }, '单独想拿文字的话:' , h('span', { style: { cursor: 'pointer', textDecoration: 'underline' }, onClick: () => { copy(raw); setMsg('读后感全文已复制') } }, '复制读后感'), ' · ', h('span', { style: { cursor: 'pointer', textDecoration: 'underline' }, onClick: () => { copy(JSON.stringify(state, null, 2)); setMsg('进度 JSON 已复制') } }, '复制进度')),
914
- ),
915
- h('div', { style: S.card },
916
- h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 6 } },
917
- h('div', { style: { fontWeight: 600 } }, '更新'),
918
- h('div', { style: { ...S.dim, fontSize: 12 } }, 'v' + ((upd && upd.current) || (state && state.version) || '')),
919
- (upd && upd.latest) ? h('div', { style: { fontSize: 12, color: upd.outdated ? C.warn : C.ok } }, 'npm 最新 ' + upd.latest) : null,
920
- ),
921
- h('div', { style: S.row },
922
- h('button', { style: S.btn, onClick: async () => {
923
- setBusy(true)
924
- try {
925
- const r = await fetch('/dsh-reading.update').then((x) => x.json())
926
- if (r && r.ok) {
927
- const d = new Date()
928
- const pad = (n) => String(n).padStart(2, '0')
929
- setUpd({ ...r, at: pad(d.getHours()) + ':' + pad(d.getMinutes()) })
930
- setMsg(r.outdated
931
- ? ('发现新版本 ' + r.latest + ':可以点「复制更新命令」,在终端里跑')
932
- : (r.latest ? ('已是最新版 ' + r.current + ',不用更新') : '查不到 npm(可能离线),稍后再试'), 'upd')
933
- } else setMsg('检测失败:' + ((r && r.error) || '未知'), 'upd')
934
- } catch (e) {
935
- setMsg('检测失败:' + String((e && e.message) || e), 'upd')
936
- } finally { setBusy(false) }
937
- } }, '检测更新'),
938
- h('button', { style: S.btn, onClick: () => { copy('dsh plugin add dsh-half-page@latest'); setMsg('更新命令已复制', 'upd') } }, '复制更新命令'),
939
- ),
940
- msgAt === 'upd' ? h('div', { style: { ...S.dim, color: (upd && upd.outdated) ? C.warn : C.ok, marginTop: 4 } }, msg) : null,
941
- h('div', { style: { ...S.dim, marginTop: 4 } }, '更新就是把 npm 上的最新版装一遍;命令可以复制出去,在终端里跑。'),
942
- ),
943
- )
944
-
915
+ ),
916
+ h('div', { style: S.card },
917
+ h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 6 } },
918
+ h('div', { style: { fontWeight: 600 } }, '更新'),
919
+ h('div', { style: { ...S.dim, fontSize: 12 } }, 'v' + ((upd && upd.current) || (state && state.version) || '')),
920
+ (upd && upd.latest) ? h('div', { style: { fontSize: 12, color: upd.outdated ? C.warn : C.ok } }, 'npm 最新 ' + upd.latest) : null,
921
+ ),
922
+ h('div', { style: S.row },
923
+ h('button', { style: S.btn, onClick: async () => {
924
+ setBusy(true)
925
+ try {
926
+ const r = await fetch('/dsh-reading.update').then((x) => x.json())
927
+ if (r && r.ok) {
928
+ const d = new Date()
929
+ const pad = (n) => String(n).padStart(2, '0')
930
+ setUpd({ ...r, at: pad(d.getHours()) + ':' + pad(d.getMinutes()) })
931
+ setMsg(r.outdated
932
+ ? ('发现新版本 ' + r.latest + ':可以点「复制更新命令」,在终端里跑')
933
+ : (r.latest ? ('已是最新版 ' + r.current + ',不用更新') : '查不到 npm(可能离线),稍后再试'), 'upd')
934
+ } else setMsg('检测失败:' + ((r && r.error) || '未知'), 'upd')
935
+ } catch (e) {
936
+ setMsg('检测失败:' + String((e && e.message) || e), 'upd')
937
+ } finally { setBusy(false) }
938
+ } }, '检测更新'),
939
+ h('button', { style: S.btn, onClick: () => { copy('dsh plugin add dsh-half-page@latest'); setMsg('更新命令已复制', 'upd') } }, '复制更新命令'),
940
+ ),
941
+ msgAt === 'upd' ? h('div', { style: { ...S.dim, color: (upd && upd.outdated) ? C.warn : C.ok, marginTop: 4 } }, msg) : null,
942
+ h('div', { style: { ...S.dim, marginTop: 4 } }, '更新就是把 npm 上的最新版装一遍;命令可以复制出去,在终端里跑。'),
943
+ ),
944
+ )
945
+
945
946
  const favTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
946
947
  h('div', { style: S.card },
947
948
  h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
package/index.js CHANGED
@@ -450,11 +450,15 @@ export function normaliseStudySlot(raw, cfg, i = 0) {
450
450
  const s = raw || {}
451
451
  const mode = s.mode === 'day' || s.mode === 'week' ? s.mode : studyModeOf(cfg)
452
452
  const dBudget = Math.min(7, Math.max(1, Math.floor(Number(s.per) || (mode === 'day' ? studyPerDayOf(cfg) : studyPerWeekOf(cfg)))))
453
+ const every = Math.min(1440, Math.max(5, Math.floor(Number(s.everyMinutes) || 30)))
454
+ const budget = Math.min(24, Math.max(1, Math.floor(Number(s.dailyBudget) || dBudget || 4)))
453
455
  return {
454
456
  id: String(s.id || ('slot-' + (i + 1))),
455
457
  enabled: s.enabled === true,
456
458
  from: String(s.from ?? ''),
457
459
  to: String(s.to ?? ''),
460
+ everyMinutes: every,
461
+ dailyBudget: budget,
458
462
  mode,
459
463
  per: dBudget,
460
464
  session: String(s.session ?? ''),
@@ -490,6 +494,8 @@ export function slotCfgOf(slot) {
490
494
  studyMode: slot.mode,
491
495
  studyPerDay: slot.per,
492
496
  studyPerWeek: slot.per,
497
+ studyEveryMinutes: Math.min(1440, Math.max(5, Math.floor(Number(slot.everyMinutes) || 30))),
498
+ studyDailyBudget: Math.min(24, Math.max(1, Math.floor(Number(slot.dailyBudget) || slot.per || 4))),
493
499
  }
494
500
  }
495
501
 
@@ -545,7 +551,13 @@ export function decideStudy({ cfg, study, now, timeline }) {
545
551
  if (!w) return { ok: false, reason: 'no-window' }
546
552
  if (!inStudyWindow(w, new Date(now))) return { ok: false, reason: 'outside' }
547
553
  const mode = studyModeOf(cfg)
548
- if (mode === 'day') {
554
+ if (Number(cfg?.studyEveryMinutes) > 0) {
555
+ // 心跳那套:只靠「距上次叫满一个频次」和「今天上限」,读没读过都不管
556
+ const budget = Math.max(1, Math.floor(Number(cfg.studyDailyBudget) || 4))
557
+ if ((Number(study.dayCount) || 0) >= budget) return { ok: false, reason: 'day-budget' }
558
+ const gap = Math.max(5, Math.floor(Number(cfg.studyEveryMinutes) || 30)) * 60000
559
+ if (study.lastAt && localDayOf(study.lastAt) === localDayOf(now) && now - study.lastAt < gap) return { ok: false, reason: 'gap' }
560
+ } else if (mode === 'day') {
549
561
  if ((Number(study.dayCount) || 0) >= studyPerDayOf(cfg)) return { ok: false, reason: 'day-budget' }
550
562
  } else {
551
563
  if (study.lastAt && localDayOf(study.lastAt) === localDayOf(now)) return { ok: false, reason: 'today-called' }
@@ -1148,7 +1160,6 @@ export function apply(ctx, rawConfig) {
1148
1160
  const dir = cfgNow.dir
1149
1161
  const st = await loadState(dir)
1150
1162
  const now = Date.now()
1151
- if (readSomethingToday(st, now)) return
1152
1163
  const slots = studySlotsOf(st, cfgNow)
1153
1164
  let changed = false
1154
1165
  for (const slot of slots) {
@@ -1234,9 +1245,9 @@ export function apply(ctx, rawConfig) {
1234
1245
  kind: 'exact',
1235
1246
  path: '/dsh-reading.state',
1236
1247
  async handler(req, res) {
1237
- const { dir, perDay, st, shelf, readToday: rt } = await stateOf()
1238
- let localVersion = ''
1239
- try { localVersion = JSON.parse(await readFile(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8')).version || '' } catch {}
1248
+ const { dir, perDay, st, shelf, readToday: rt } = await stateOf()
1249
+ let localVersion = ''
1250
+ try { localVersion = JSON.parse(await readFile(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8')).version || '' } catch {}
1240
1251
 
1241
1252
  const cfgNow = await config()
1242
1253
  const rid0 = readerParam(st, new URL(req.url || '/', 'http://localhost')).id
@@ -1303,6 +1314,7 @@ export function apply(ctx, rawConfig) {
1303
1314
  const c = slotStudyOf(s, Date.now())
1304
1315
  return {
1305
1316
  id: s.id, index: i, enabled: s.enabled, from: s.from, to: s.to, mode: s.mode, per: s.per,
1317
+ everyMinutes: s.everyMinutes, dailyBudget: s.dailyBudget,
1306
1318
  session: s.session, sessionName: (liveSessions.find((x) => x.id === s.session) || {}).title || '',
1307
1319
  lastAt: c.lastAt, dayCount: c.dayCount, weekCount: c.weekCount,
1308
1320
  }
@@ -1449,13 +1461,13 @@ export function apply(ctx, rawConfig) {
1449
1461
  auth: sameSiteAuth,
1450
1462
  kind: 'exact',
1451
1463
  path: '/dsh-reading.backupFile',
1452
- async handler(req, res) {
1453
- try {
1454
- const { appendFile: af } = await import('node:fs/promises')
1455
- const { tmpdir: td } = await import('node:os')
1456
- const { join: jn } = await import('node:path')
1457
- await af(jn(td(), 'hp-backup-hit.log'), new Date().toISOString() + ' ' + req.method + ' origin=' + (req.headers.origin || '-') + ' host=' + (req.headers.host || '-') + '\n')
1458
- } catch {}
1464
+ async handler(req, res) {
1465
+ try {
1466
+ const { appendFile: af } = await import('node:fs/promises')
1467
+ const { tmpdir: td } = await import('node:os')
1468
+ const { join: jn } = await import('node:path')
1469
+ await af(jn(td(), 'hp-backup-hit.log'), new Date().toISOString() + ' ' + req.method + ' origin=' + (req.headers.origin || '-') + ' host=' + (req.headers.host || '-') + '\n')
1470
+ } catch {}
1459
1471
 
1460
1472
  res.setHeader('content-type', 'application/json; charset=utf-8')
1461
1473
  try {
@@ -1530,7 +1542,7 @@ export function apply(ctx, rawConfig) {
1530
1542
 
1531
1543
  // 查 npm 上最新版(面板「检测更新」用)
1532
1544
  const checkUpdate = async () => {
1533
- const here = dirname(fileURLToPath(import.meta.url))
1545
+ const here = dirname(fileURLToPath(import.meta.url))
1534
1546
 
1535
1547
  let current = ''
1536
1548
  try {
@@ -1571,83 +1583,83 @@ export function apply(ctx, rawConfig) {
1571
1583
  // 弹系统「另存为」对话框:让用户自己选放哪(面板在 iframe 里不能自己弹)
1572
1584
  // 对话框脚本内嵌,运行时落到临时目录:不依赖安装位置的 toolkit(换机器也能用)
1573
1585
  // 对话框脚本内嵌,运行时落到临时目录:不依赖安装位置的 toolkit(换机器也能用)
1574
- const hpDialogOverlay = (mode, suggested, source) => {
1575
- const q = (s) => "'" + String(s || '').replace(/'/g, "''") + "'"
1576
- return [
1577
- 'Add-Type -AssemblyName System.Windows.Forms | Out-Null',
1578
- 'Add-Type -AssemblyName System.Drawing | Out-Null',
1579
- `$Mode = ${q(mode)}`,
1580
- `$Suggested = ${q(suggested)}`,
1581
- `$Source = ${q(source)}`,
1582
- '$owner = New-Object System.Windows.Forms.Form',
1583
- '$owner.TopMost = $true',
1584
- '$owner.ShowInTaskbar = $false',
1585
- '$owner.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None',
1586
- '$owner.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen',
1587
- '$owner.Size = New-Object System.Drawing.Size(1,1)',
1588
- '$owner.Opacity = 0',
1589
- '$owner.Show()',
1590
- '$owner.Activate()',
1591
- 'try {',
1592
- ' if ($Mode -eq "save") {',
1593
- ' $dlg = New-Object System.Windows.Forms.SaveFileDialog',
1594
- ' $dlg.Filter = "JSON (*.json)|*.json|All files (*.*)|*.*"',
1595
- ' $dlg.FileName = $Suggested',
1596
- ' $dlg.OverwritePrompt = $true',
1597
- ' } else {',
1598
- ' $dlg = New-Object System.Windows.Forms.OpenFileDialog',
1599
- ' $dlg.Filter = "JSON (*.json)|*.json|All files (*.*)|*.*"',
1600
- ' }',
1601
- ' $r = $dlg.ShowDialog($owner)',
1602
- ' if ($r -ne [System.Windows.Forms.DialogResult]::OK) { $owner.Close(); Write-Output "CANCELLED"; exit 0 }',
1603
- ' $target = $dlg.FileName',
1604
- ' if ($Mode -eq "save" -and $Source -ne "") { Copy-Item -LiteralPath $Source -Destination $target -Force }',
1605
- ' $owner.Close()',
1606
- ' Write-Output $target',
1607
- ' exit 0',
1608
- '} catch {',
1609
- ' $owner.Close()',
1610
- ' Write-Output ("ERROR " + $_.Exception.Message)',
1611
- ' exit 1',
1612
- '}',
1613
- '',
1614
- ].join('\r\n')
1615
- }
1616
-
1617
- const hpDialogLog = async (line) => {
1618
- try {
1619
- await appendFile(join(tmpdir(), 'hp-dialog.log'), new Date().toISOString() + ' ' + line + '\n')
1620
- } catch {}
1621
- }
1622
-
1623
- const runDialog = (mode, suggested, source) => new Promise((resolve2) => {
1624
- let p
1625
- try {
1626
- const script = hpDialogOverlay(mode, suggested, source)
1627
- const b64 = Buffer.from(script, 'utf16le').toString('base64')
1628
- p = spawn('powershell.exe', ['-NoProfile', '-STA', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', b64], { windowsHide: true })
1629
- } catch (e) {
1630
- hpDialogLog('spawn-throw ' + String((e && e.message) || e))
1631
- resolve2({ ok: false, error: String((e && e.message) || e) })
1632
- return
1633
- }
1634
- let out = ''
1635
- let err = ''
1636
- p.stdout.on('data', (d) => { out += String(d) })
1637
- p.stderr.on('data', (d) => { err += String(d) })
1638
- p.on('error', (e) => {
1639
- hpDialogLog('spawn-error ' + String((e && e.message) || e))
1640
- resolve2({ ok: false, error: String((e && e.message) || e) })
1641
- })
1642
- p.on('close', (code) => {
1643
- const line = out.trim().split(/\r?\n/).filter(Boolean).pop() || ''
1644
- hpDialogLog('mode=' + mode + ' exit=' + code + ' out=' + JSON.stringify(line).slice(0, 200) + ' err=' + JSON.stringify(err.trim()).slice(0, 300))
1645
- if (!line || line === 'CANCELLED') resolve2({ ok: false, cancelled: true })
1646
- else if (line.startsWith('ERROR')) resolve2({ ok: false, error: line.slice(6).trim() })
1647
- else resolve2({ ok: true, path: line })
1648
- })
1649
- })
1650
-
1586
+ const hpDialogOverlay = (mode, suggested, source) => {
1587
+ const q = (s) => "'" + String(s || '').replace(/'/g, "''") + "'"
1588
+ return [
1589
+ 'Add-Type -AssemblyName System.Windows.Forms | Out-Null',
1590
+ 'Add-Type -AssemblyName System.Drawing | Out-Null',
1591
+ `$Mode = ${q(mode)}`,
1592
+ `$Suggested = ${q(suggested)}`,
1593
+ `$Source = ${q(source)}`,
1594
+ '$owner = New-Object System.Windows.Forms.Form',
1595
+ '$owner.TopMost = $true',
1596
+ '$owner.ShowInTaskbar = $false',
1597
+ '$owner.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None',
1598
+ '$owner.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen',
1599
+ '$owner.Size = New-Object System.Drawing.Size(1,1)',
1600
+ '$owner.Opacity = 0',
1601
+ '$owner.Show()',
1602
+ '$owner.Activate()',
1603
+ 'try {',
1604
+ ' if ($Mode -eq "save") {',
1605
+ ' $dlg = New-Object System.Windows.Forms.SaveFileDialog',
1606
+ ' $dlg.Filter = "JSON (*.json)|*.json|All files (*.*)|*.*"',
1607
+ ' $dlg.FileName = $Suggested',
1608
+ ' $dlg.OverwritePrompt = $true',
1609
+ ' } else {',
1610
+ ' $dlg = New-Object System.Windows.Forms.OpenFileDialog',
1611
+ ' $dlg.Filter = "JSON (*.json)|*.json|All files (*.*)|*.*"',
1612
+ ' }',
1613
+ ' $r = $dlg.ShowDialog($owner)',
1614
+ ' if ($r -ne [System.Windows.Forms.DialogResult]::OK) { $owner.Close(); Write-Output "CANCELLED"; exit 0 }',
1615
+ ' $target = $dlg.FileName',
1616
+ ' if ($Mode -eq "save" -and $Source -ne "") { Copy-Item -LiteralPath $Source -Destination $target -Force }',
1617
+ ' $owner.Close()',
1618
+ ' Write-Output $target',
1619
+ ' exit 0',
1620
+ '} catch {',
1621
+ ' $owner.Close()',
1622
+ ' Write-Output ("ERROR " + $_.Exception.Message)',
1623
+ ' exit 1',
1624
+ '}',
1625
+ '',
1626
+ ].join('\r\n')
1627
+ }
1628
+
1629
+ const hpDialogLog = async (line) => {
1630
+ try {
1631
+ await appendFile(join(tmpdir(), 'hp-dialog.log'), new Date().toISOString() + ' ' + line + '\n')
1632
+ } catch {}
1633
+ }
1634
+
1635
+ const runDialog = (mode, suggested, source) => new Promise((resolve2) => {
1636
+ let p
1637
+ try {
1638
+ const script = hpDialogOverlay(mode, suggested, source)
1639
+ const b64 = Buffer.from(script, 'utf16le').toString('base64')
1640
+ p = spawn('powershell.exe', ['-NoProfile', '-STA', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', b64], { windowsHide: true })
1641
+ } catch (e) {
1642
+ hpDialogLog('spawn-throw ' + String((e && e.message) || e))
1643
+ resolve2({ ok: false, error: String((e && e.message) || e) })
1644
+ return
1645
+ }
1646
+ let out = ''
1647
+ let err = ''
1648
+ p.stdout.on('data', (d) => { out += String(d) })
1649
+ p.stderr.on('data', (d) => { err += String(d) })
1650
+ p.on('error', (e) => {
1651
+ hpDialogLog('spawn-error ' + String((e && e.message) || e))
1652
+ resolve2({ ok: false, error: String((e && e.message) || e) })
1653
+ })
1654
+ p.on('close', (code) => {
1655
+ const line = out.trim().split(/\r?\n/).filter(Boolean).pop() || ''
1656
+ hpDialogLog('mode=' + mode + ' exit=' + code + ' out=' + JSON.stringify(line).slice(0, 200) + ' err=' + JSON.stringify(err.trim()).slice(0, 300))
1657
+ if (!line || line === 'CANCELLED') resolve2({ ok: false, cancelled: true })
1658
+ else if (line.startsWith('ERROR')) resolve2({ ok: false, error: line.slice(6).trim() })
1659
+ else resolve2({ ok: true, path: line })
1660
+ })
1661
+ })
1662
+
1651
1663
  ctx.effect(() =>
1652
1664
  ctx.webServer.register({
1653
1665
  auth: sameSiteAuth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.4.43",
3
+ "version": "0.4.48",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",
@@ -26,7 +26,8 @@
26
26
  "icon.svg",
27
27
  "assets/*",
28
28
  "books/*.txt",
29
- "screenshots.json"
29
+ "screenshots.json",
30
+ "CHANGELOG.md"
30
31
  ],
31
32
  "dsh": {
32
33
  "bundle": {