dsh-half-page 0.0.0-stage → 0.3.19
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 +58 -2
- package/client.js +453 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +7 -0
- package/index.js +924 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +42 -3
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 半页 · dsh-half-page
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一间会自己读书的书房。给 AI 用的,不是给你的待办清单。
|
|
4
|
+
|
|
5
|
+
装上之后,你的智能体会有一小块自己的地方:一章一章地读一本书,记下读到哪儿了;读完想说什么,就写在那个人章边上;想写点自己的东西(小说、随笔、画),也能放在这儿一起看。
|
|
6
|
+
|
|
7
|
+
打开面板能看见:它今天翻了几页、读到第几章、写了什么——以及它是不是最近根本没动过这本书(那也是信息)。
|
|
8
|
+
|
|
9
|
+
## 它是谁的
|
|
10
|
+
|
|
11
|
+
是**智能体自己的房间**。
|
|
12
|
+
|
|
13
|
+
它装好之后会往自己的系统提示里加几条:想读就读、读不下去就停、每日上限是提醒不是配额、不用交读书报告。请不要把这些当成任务派给它,也别催它"今天怎么没读书"。
|
|
14
|
+
|
|
15
|
+
## 功能
|
|
16
|
+
|
|
17
|
+
- **一章一章读**:自动分章,随时停在任意一章,下次接着来
|
|
18
|
+
- **读后感**:一章可以写一两句,只记真的打动它的;面板按书分组、可分页、可收藏
|
|
19
|
+
- **署名**:写读后感时带上 `by`,每条下面会标出是谁写的(多只智能体共用一个书房时有用)
|
|
20
|
+
- **她的作品**:面板里能看它自己写的东西,带状态标签(在写 / 写完了 / 搁下了)
|
|
21
|
+
- **导入书**:面板里直接选 `.txt` / `.md` 文件,不用手动拷目录
|
|
22
|
+
- **下架**:从书架拿下来的书会移到 `books/.trash/`,不会真删;读后感也不会跟着消失
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
dsh plugin add dsh-half-page
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
装好之后在 DSH 的插件设置里打开它,左侧会多一个「半页」。
|
|
31
|
+
|
|
32
|
+
## 数据放在哪
|
|
33
|
+
|
|
34
|
+
都在 `~/.dsh/reading/`:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
~/.dsh/reading/
|
|
38
|
+
├── books/ 书(.txt / .md)
|
|
39
|
+
│ └── .trash/ 下架的书挪到这儿,可手工找回
|
|
40
|
+
├── 读后感.md 所有读后感,按 ## 书名 / ### 章名 分块
|
|
41
|
+
├── 作品/ 它自己写的东西
|
|
42
|
+
└── state.json 读到哪了
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。
|
|
46
|
+
|
|
47
|
+
## 工具
|
|
48
|
+
|
|
49
|
+
| 工具 | 用途 |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `reading_shelf` | 书架与进度 |
|
|
52
|
+
| `reading_next` | 打开下一章(或指定章) |
|
|
53
|
+
| `reading_note` | 给这章写一两句读后感,可带 `by` |
|
|
54
|
+
| `reading_search` | 在书里搜词,返回第几章、哪一行 |
|
|
55
|
+
| `reading_recap` | 已读部分压成一页 |
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-half-page — 半页(Client 半边)
|
|
3
|
+
* 只做统计面板:读到哪、写了什么、她的作品;不显示正文(点「显示原文」才取)。
|
|
4
|
+
*/
|
|
5
|
+
// 注意:下面的 id 必须等于 package.json 的 name(DSH 按入口名判重,不一致会白屏报 duplicate factory registration)
|
|
6
|
+
window.__ModuleLoader__.load({
|
|
7
|
+
id: 'dsh-half-page',
|
|
8
|
+
factory(require) {
|
|
9
|
+
const React = require('react')
|
|
10
|
+
const h = React.createElement
|
|
11
|
+
const { useState, useEffect, useMemo } = React
|
|
12
|
+
|
|
13
|
+
// 浅色主题,跟 DSH 主界面一致(深底浅字会和白界面不和谐)
|
|
14
|
+
const C = {
|
|
15
|
+
text: '#1c2430', dim: '#5d6878', line: '#e1e6ee',
|
|
16
|
+
bg: '#ffffff', card: '#f7f9fc', accent: '#2f6fed', ok: '#12876b', warn: '#b46a00',
|
|
17
|
+
}
|
|
18
|
+
const S = {
|
|
19
|
+
tag: { fontSize: 11, padding: '1px 7px', borderRadius: 9, border: '1px solid ' + C.line, background: C.card, color: C.dim, cursor: 'pointer' },
|
|
20
|
+
tagOn: { fontSize: 11, padding: '1px 7px', borderRadius: 9, border: '1px solid ' + C.accent, background: '#eaf1ff', color: C.accent, cursor: 'pointer' },
|
|
21
|
+
|
|
22
|
+
wrap: { padding: '14px 16px', fontSize: 13, color: C.text, display: 'flex', flexDirection: 'column', gap: 12, height: '100%', boxSizing: 'border-box', overflow: 'auto', background: C.bg },
|
|
23
|
+
row: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
|
|
24
|
+
dim: { color: C.dim, fontSize: 12 },
|
|
25
|
+
card: { border: '1px solid ' + C.line, borderRadius: 10, padding: '10px 12px', background: C.card },
|
|
26
|
+
btn: { border: '1px solid ' + C.line, background: '#fff', color: C.text, borderRadius: 8, padding: '4px 10px', fontSize: 12, cursor: 'pointer' },
|
|
27
|
+
btnOn: { border: '1px solid ' + C.accent, background: 'rgba(47,111,237,0.10)', color: C.accent, borderRadius: 8, padding: '4px 10px', fontSize: 12, cursor: 'pointer' },
|
|
28
|
+
tab: (on) => ({ padding: '5px 14px', borderRadius: 8, cursor: 'pointer', fontSize: 13, color: on ? '#fff' : C.dim, background: on ? C.accent : '#fff', border: '1px solid ' + (on ? C.accent : C.line) }),
|
|
29
|
+
bar: { height: 6, borderRadius: 99, background: '#e8edf5', overflow: 'hidden', flex: 1, minWidth: 100 },
|
|
30
|
+
fill: { height: '100%', background: 'linear-gradient(90deg,#2f6fed,#12876b)' },
|
|
31
|
+
note: { borderLeft: '2px solid rgba(18,135,107,0.45)', paddingLeft: 10, marginBottom: 8, lineHeight: 1.7, whiteSpace: 'pre-wrap' },
|
|
32
|
+
text: { whiteSpace: 'pre-wrap', lineHeight: 1.75, fontSize: 13, maxHeight: 360, overflow: 'auto', background: '#fff', borderRadius: 8, padding: '10px 12px', border: '1px solid ' + C.line },
|
|
33
|
+
item: { display: 'flex', alignItems: 'center', gap: 8, padding: '6px 8px', borderRadius: 8, border: '1px solid transparent' },
|
|
34
|
+
input: { background: '#fff', color: C.text, border: '1px solid ' + C.line, borderRadius: 8, padding: '4px 8px', fontSize: 13, width: 72 },
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fmt = (n) => n >= 1048576 ? (n / 1048576).toFixed(1) + 'M' : n >= 1024 ? Math.round(n / 1024) + 'K' : String(n)
|
|
38
|
+
const copy = (t) => { try { navigator.clipboard.writeText(t) } catch {} }
|
|
39
|
+
|
|
40
|
+
async function getJson(url, opt) {
|
|
41
|
+
const r = await fetch(url, opt)
|
|
42
|
+
return r.json()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 把读后感 md 拆成 [{book, chapters:[{title, lines:[]}], raw}]
|
|
46
|
+
function parseNotes(md) {
|
|
47
|
+
const out = []
|
|
48
|
+
let book = null, ch = null
|
|
49
|
+
for (const line of String(md || '').split(/\r?\n/)) {
|
|
50
|
+
if (/^##\s+/.test(line)) {
|
|
51
|
+
book = { book: line.replace(/^##\s+/, '').trim(), chapters: [] }
|
|
52
|
+
out.push(book); ch = null
|
|
53
|
+
} else if (/^###\s+/.test(line)) {
|
|
54
|
+
ch = { title: line.replace(/^###\s+/, '').trim(), lines: [] }
|
|
55
|
+
if (book) book.chapters.push(ch)
|
|
56
|
+
} else if (/^[-*]\s+/.test(line)) {
|
|
57
|
+
if (ch) ch.lines.push(line.replace(/^[-*]\s+/, ''))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function Panel() {
|
|
64
|
+
const [state, setState] = useState(null)
|
|
65
|
+
const [confirmId, setConfirmId] = useState('')
|
|
66
|
+
const [tab, setTab] = useState('read')
|
|
67
|
+
const [raw, setRaw] = useState('')
|
|
68
|
+
const [showRaw, setShowRaw] = useState(false)
|
|
69
|
+
const [works, setWorks] = useState(null)
|
|
70
|
+
const [opened, setOpened] = useState(null)
|
|
71
|
+
const [cfg, setCfg] = useState(null)
|
|
72
|
+
const [msg, setMsg] = useState('')
|
|
73
|
+
const [busy, setBusy] = useState(false)
|
|
74
|
+
const [recent, setRecent] = useState(null)
|
|
75
|
+
const [noteView, setNoteView] = useState({})
|
|
76
|
+
const NOTE_PAGE = 10
|
|
77
|
+
let importPath = ''
|
|
78
|
+
|
|
79
|
+
const load = async () => {
|
|
80
|
+
try {
|
|
81
|
+
const st = await getJson('/dsh-reading.state')
|
|
82
|
+
setState(st)
|
|
83
|
+
if (st && st.notes) setRaw(st.notes)
|
|
84
|
+
const c = await getJson('/dsh-reading.config')
|
|
85
|
+
if (c && c.ok) setCfg(c.config || {})
|
|
86
|
+
const rc = await getJson('/dsh-reading.recent')
|
|
87
|
+
if (rc && rc.ok) setRecent(rc)
|
|
88
|
+
} catch (e) { setMsg('读不到状态:' + String(e && e.message || e)) }
|
|
89
|
+
}
|
|
90
|
+
useEffect(() => { load() }, [])
|
|
91
|
+
|
|
92
|
+
const notes = useMemo(() => parseNotes(raw), [raw])
|
|
93
|
+
const cur = state && state.books && state.books.find((b) => b.id === state.current)
|
|
94
|
+
const favs = (cfg && cfg.favorites) || []
|
|
95
|
+
|
|
96
|
+
const advance = async () => {
|
|
97
|
+
if (busy) return
|
|
98
|
+
setBusy(true)
|
|
99
|
+
try {
|
|
100
|
+
const r = await getJson('/dsh-reading.advance', { method: 'POST' })
|
|
101
|
+
if (r && r.ok) { setMsg('推进到第 ' + r.chapter + ' 章'); await load() }
|
|
102
|
+
else setMsg('没推进:' + (r && r.error || '未知'))
|
|
103
|
+
} finally { setBusy(false) }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const backOne = async () => {
|
|
107
|
+
if (busy) return
|
|
108
|
+
setBusy(true)
|
|
109
|
+
try {
|
|
110
|
+
const r = await getJson('/dsh-reading.back', { method: 'POST' })
|
|
111
|
+
if (r && r.ok) { setMsg('退回第 ' + r.chapter + ' 章'); await load() }
|
|
112
|
+
else setMsg('没退:' + (r && r.error || '未知'))
|
|
113
|
+
} finally { setBusy(false) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
const STATES = ['在写', '写完了', '搁下了']
|
|
118
|
+
const cycleStatus = async (f) => {
|
|
119
|
+
const i = STATES.indexOf(f.status || '')
|
|
120
|
+
const next = i < 0 ? STATES[0] : (i === STATES.length - 1 ? '' : STATES[i + 1])
|
|
121
|
+
await fetch('/dsh-reading.workstatus', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ rel: f.rel, status: next }) })
|
|
122
|
+
await loadWorks()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const BOOK_STATES = ['在读', '已读完', '弃坑']
|
|
126
|
+
const removeBook = async (id) => {
|
|
127
|
+
setConfirmId('')
|
|
128
|
+
await getJson('/dsh-reading.removeBook', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id }) })
|
|
129
|
+
const j = await getJson('/dsh-reading.state')
|
|
130
|
+
if (j && j.ok) setState(j)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const cycleBook = async (b) => {
|
|
134
|
+
const i = BOOK_STATES.indexOf(b.status || '')
|
|
135
|
+
const next = i < 0 ? BOOK_STATES[0] : (i === BOOK_STATES.length - 1 ? '' : BOOK_STATES[i + 1])
|
|
136
|
+
await getJson('/dsh-reading.bookstatus', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: b.id, status: next }) })
|
|
137
|
+
const j = await getJson('/dsh-reading.state')
|
|
138
|
+
if (j && j.ok) setState(j)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const loadWorks = async () => {
|
|
142
|
+
const r = await getJson('/dsh-reading.works')
|
|
143
|
+
if (r && r.ok) setWorks(r) ; else setMsg('作品目录读不到:' + (r && r.error))
|
|
144
|
+
}
|
|
145
|
+
const openFile = async (f) => {
|
|
146
|
+
if (opened && opened.path === f.path) return setOpened(null)
|
|
147
|
+
if (f.kind !== 'text') return setOpened({ ...f, text: '(' + f.kind + ',路径:' + f.path + ')' })
|
|
148
|
+
const r = await getJson('/dsh-reading.file?path=' + encodeURIComponent(f.path))
|
|
149
|
+
setOpened({ ...f, text: r && r.ok ? r.text : '读不到:' + (r && r.error) })
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const toggleFav = async (key) => {
|
|
153
|
+
const next = favs.includes(key) ? favs.filter((x) => x !== key) : favs.concat(key)
|
|
154
|
+
const r = await getJson('/dsh-reading.config', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ favorites: next }) })
|
|
155
|
+
if (r && r.ok) { setCfg(r.config); setMsg(favs.includes(key) ? '已取消收藏' : '已收藏') }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const saveCfg = async (patch) => {
|
|
159
|
+
const r = await getJson('/dsh-reading.config', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(patch) })
|
|
160
|
+
if (r && r.ok) { setCfg(r.config); setMsg('已保存') ; await load() } else setMsg('保存失败:' + (r && r.error))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const head = h('div', { style: S.card },
|
|
164
|
+
h('div', { style: S.row },
|
|
165
|
+
h('div', { style: { fontWeight: 600, fontSize: 14 } }, cur ? ('正在读《' + cur.id + '》') : '还没导入书'),
|
|
166
|
+
h('div', { style: S.dim }, state ? ('今天 ' + state.readToday + '/' + state.perDay + ' 章') : ''),
|
|
167
|
+
h('div', { style: { flex: 1 } }),
|
|
168
|
+
h('button', { style: S.btn, onClick: load }, '刷新'),
|
|
169
|
+
),
|
|
170
|
+
cur ? h('div', { style: { ...S.row, marginTop: 8 } },
|
|
171
|
+
h('div', { style: S.bar }, h('div', { style: { ...S.fill, width: Math.min(100, ((cur.readThrough || 0) / (cur.chapters || 1)) * 100) + '%' } })),
|
|
172
|
+
h('div', { style: S.dim }, '读到第 ' + (cur.readThrough || 0) + ' / ' + cur.chapters + ' 章'),
|
|
173
|
+
) : null,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
const tabs = h('div', { style: S.row },
|
|
177
|
+
['read', 'works', 'set'].map((k) => h('div', {
|
|
178
|
+
key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if (k === 'works' && !works) loadWorks() },
|
|
179
|
+
}, k === 'read' ? '读书' : k === 'works' ? '她的作品' : '设置')),
|
|
180
|
+
h('div', { style: { flex: 1 } }),
|
|
181
|
+
msg ? h('div', { style: { ...S.dim, color: C.ok } }, msg) : null,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
const readTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
185
|
+
// 近况卡
|
|
186
|
+
h('div', { style: S.card },
|
|
187
|
+
h('div', { style: S.row },
|
|
188
|
+
h('div', { style: { fontWeight: 600 } }, '近况'),
|
|
189
|
+
h('div', { style: { flex: 1 } }),
|
|
190
|
+
h('div', { style: S.dim }, recent ? (recent.today || '') : ''),
|
|
191
|
+
),
|
|
192
|
+
h('div', { style: { marginTop: 6, marginBottom: 6 } }, recent && recent.status ? recent.status : '还没什么可报的。'),
|
|
193
|
+
recent && recent.mood
|
|
194
|
+
? h('div', { style: { marginBottom: 6 } }, h('span', { style: S.tagOn }, recent.mood))
|
|
195
|
+
: null,
|
|
196
|
+
recent && recent.days && recent.days.length
|
|
197
|
+
? h('div', { style: { marginBottom: 4 } },
|
|
198
|
+
h('div', { style: S.dim }, '这几天翻过的:'),
|
|
199
|
+
recent.days.map((d, i) => h('div', { key: i, style: S.row },
|
|
200
|
+
h('div', { style: S.dim }, d.day),
|
|
201
|
+
h('div', { style: { flex: 1 } }, '《' + d.book + '》' + d.chapters + ' 章'),
|
|
202
|
+
)),
|
|
203
|
+
)
|
|
204
|
+
: null,
|
|
205
|
+
recent && recent.works && recent.works.length
|
|
206
|
+
? h('div', null,
|
|
207
|
+
h('div', { style: S.dim }, '最近碰过的稿子:'),
|
|
208
|
+
recent.works.map((w, i) => h('div', { key: i, style: S.row },
|
|
209
|
+
h('div', { style: { flex: 1 } },
|
|
210
|
+
h('div', null, w.rel),
|
|
211
|
+
w.note ? h('div', { style: { ...S.dim, fontSize: 11 } }, w.note) : null,
|
|
212
|
+
),
|
|
213
|
+
h('div', { style: S.dim }, w.days === 0 ? '今天' : w.days + ' 天前'),
|
|
214
|
+
)),
|
|
215
|
+
)
|
|
216
|
+
: null,
|
|
217
|
+
),
|
|
218
|
+
|
|
219
|
+
h('div', { style: S.card },
|
|
220
|
+
h('div', { style: S.row },
|
|
221
|
+
h('div', { style: { fontWeight: 600 } }, '这一本'),
|
|
222
|
+
h('div', { style: { flex: 1 } }),
|
|
223
|
+
h('button', { style: S.btn, onClick: backOne, disabled: busy }, busy ? '…' : '退一章'),
|
|
224
|
+
h('button', { style: S.btn, onClick: advance, disabled: busy }, busy ? '…' : '推进一章'),
|
|
225
|
+
h('button', { style: showRaw ? S.btnOn : S.btn, onClick: async () => {
|
|
226
|
+
if (!showRaw && cur) {
|
|
227
|
+
const r = await getJson('/dsh-reading.chapter?book=' + encodeURIComponent(cur.id) + '&n=' + (cur.readThrough || 1))
|
|
228
|
+
if (r && r.ok) setOpened({ path: 'chapter', text: r.text, title: r.title })
|
|
229
|
+
}
|
|
230
|
+
setShowRaw(!showRaw)
|
|
231
|
+
} }, showRaw ? '收起原文' : '显示原文'),
|
|
232
|
+
),
|
|
233
|
+
showRaw && opened && opened.path === 'chapter'
|
|
234
|
+
? h('div', { style: { ...S.text, marginTop: 8 } }, (opened.title ? opened.title + '\n\n' : '') + opened.text)
|
|
235
|
+
: null,
|
|
236
|
+
),
|
|
237
|
+
h('div', { style: S.card },
|
|
238
|
+
h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '书架'),
|
|
239
|
+
(state && state.books && state.books.length) ? state.books.map((b, i) => {
|
|
240
|
+
const done = (b.readThrough || 0) >= (b.chapters || 1)
|
|
241
|
+
return h('div', { key: i, style: S.row },
|
|
242
|
+
h('div', { style: { flex: 1, color: b.id === (state && state.current) ? C.accent : C.text } }, b.id),
|
|
243
|
+
h('div', { style: S.dim }, (b.readThrough || 0) + '/' + b.chapters),
|
|
244
|
+
h('button', {
|
|
245
|
+
style: b.status === '弃坑' ? { ...S.tag, color: C.warn } : (done || b.status === '已读完' ? { ...S.tag, color: C.ok } : S.tag),
|
|
246
|
+
title: '点一下换状态:在读 → 已读完 → 弃坑 → 不标',
|
|
247
|
+
onClick: () => cycleBook(b),
|
|
248
|
+
}, b.status || (done ? '已读完' : '在读')),
|
|
249
|
+
h('button', {
|
|
250
|
+
style: { ...S.tag, color: confirmId === b.id ? C.warn : C.dim, marginLeft: 6 },
|
|
251
|
+
title: confirmId === b.id
|
|
252
|
+
? '再点一下就从书架拿下来(文件会移到 books/.trash,读后感不动)'
|
|
253
|
+
: '从书架拿下来(文件移到 books/.trash,可手工找回;读后感不动)',
|
|
254
|
+
onClick: () => (confirmId === b.id ? removeBook(b.id) : setConfirmId(b.id)),
|
|
255
|
+
}, confirmId === b.id ? '确认?' : '下架'),
|
|
256
|
+
)
|
|
257
|
+
}) : h('div', { style: S.dim }, '还没有书。'),
|
|
258
|
+
),
|
|
259
|
+
h('div', { style: S.card },
|
|
260
|
+
h('div', { style: { ...S.dim, marginBottom: 6 } }, '读后感(按书分组)'),
|
|
261
|
+
notes.length ? notes.map((bk, bi) => {
|
|
262
|
+
const v = noteView[bi] || {}
|
|
263
|
+
const all = !!v.all
|
|
264
|
+
const total = bk.chapters.length
|
|
265
|
+
const pages = Math.max(1, Math.ceil(total / NOTE_PAGE))
|
|
266
|
+
const page = Math.min(v.page || 0, pages - 1)
|
|
267
|
+
const list = all ? bk.chapters : bk.chapters.slice(page * NOTE_PAGE, page * NOTE_PAGE + NOTE_PAGE)
|
|
268
|
+
const setView = (patch) => setNoteView(Object.assign({}, noteView, { [bi]: Object.assign({}, v, patch) }))
|
|
269
|
+
const paged = total > NOTE_PAGE
|
|
270
|
+
return h('div', { key: bi, style: { marginBottom: 10 } },
|
|
271
|
+
h('div', { style: { ...S.row, marginBottom: 4 } },
|
|
272
|
+
h('div', { style: { fontWeight: 600 } }, bk.book),
|
|
273
|
+
h('div', { style: S.dim }, total + ' 章'),
|
|
274
|
+
h('div', { style: { flex: 1 } }),
|
|
275
|
+
paged ? h('button', { style: S.btn, disabled: page <= 0, onClick: () => setView({ page: page - 1 }) }, '‹') : null,
|
|
276
|
+
paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
|
|
277
|
+
paged ? h('button', { style: S.btn, disabled: all || page >= pages - 1, onClick: () => setView({ page: page + 1 }) }, '›') : null,
|
|
278
|
+
paged ? h('button', { style: all ? S.btnOn : S.btn, onClick: () => setView({ all: !all, page: 0 }) }, all ? '分页' : '全部') : null,
|
|
279
|
+
h('button', { style: S.btn, onClick: () => copy(bk.chapters.map((c) => '## ' + c.title + '\n' + c.lines.join('\n')).join('\n\n')) }, '复制这本'),
|
|
280
|
+
),
|
|
281
|
+
list.map((c, ci) => h('div', { key: ci, style: { marginBottom: 6 } },
|
|
282
|
+
h('div', { style: S.row },
|
|
283
|
+
h('div', { style: { ...S.dim, color: C.warn } }, c.title),
|
|
284
|
+
h('button', { style: S.btn, onClick: () => toggleFav(bk.book + '|' + c.title) }, favs.includes(bk.book + '|' + c.title) ? '★' : '☆'),
|
|
285
|
+
h('button', { style: S.btn, onClick: () => copy(c.lines.join('\n')) }, '复制'),
|
|
286
|
+
),
|
|
287
|
+
c.lines.map((l, li) => h('div', { key: li, style: /^↳/.test(l) ? { ...S.dim, marginTop: 4 } : S.note }, l)),
|
|
288
|
+
)),
|
|
289
|
+
)
|
|
290
|
+
}) : h('div', { style: S.dim }, '还没写过。读完一章记两句,这里就有了。'),
|
|
291
|
+
),
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
const worksTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
295
|
+
h('div', { style: S.card },
|
|
296
|
+
h('div', { style: S.row },
|
|
297
|
+
h('div', { style: { fontWeight: 600 } }, '她的作品'),
|
|
298
|
+
h('div', { style: S.dim }, works ? (works.root + ' · ' + works.files.length + ' 个文件') : ''),
|
|
299
|
+
h('div', { style: { flex: 1 } }),
|
|
300
|
+
h('button', { style: S.btn, onClick: loadWorks }, '重新扫描'),
|
|
301
|
+
),
|
|
302
|
+
!works ? h('div', { style: { ...S.dim, marginTop: 8 } }, '点「重新扫描」列出作品目录。') :
|
|
303
|
+
(works.files.length ? works.files.map((f, i) => h('div', { key: i, style: { ...S.item, borderTop: '1px solid ' + C.line } },
|
|
304
|
+
h('div', { style: { flex: 1, cursor: 'pointer' }, onClick: () => openFile(f) }, f.rel),
|
|
305
|
+
h('button', {
|
|
306
|
+
style: f.status === '在写' ? S.tagOn : S.tag,
|
|
307
|
+
title: '点一下换状态:在写 → 写完了 → 搁下了 → 不标',
|
|
308
|
+
onClick: () => cycleStatus(f),
|
|
309
|
+
}, f.status || '—'),
|
|
310
|
+
h('div', { style: S.dim }, f.kind + ' · ' + fmt(f.size)),
|
|
311
|
+
h('button', { style: S.btn, onClick: () => toggleFav('file:' + f.path) }, favs.includes('file:' + f.path) ? '★' : '☆'),
|
|
312
|
+
f.kind === 'text' ? h('button', { style: S.btn, onClick: async () => {
|
|
313
|
+
const r = await getJson('/dsh-reading.file?path=' + encodeURIComponent(f.path))
|
|
314
|
+
if (r && r.ok) { copy(r.text); setMsg('已复制全文') }
|
|
315
|
+
} }, '复制') : h('button', { style: S.btn, onClick: () => { copy(f.path); setMsg('已复制路径') } }, '复制路径'),
|
|
316
|
+
)) : h('div', { style: { ...S.dim, marginTop: 8 } }, '这里还是空的:把 .md 或 .txt 放进 ' + works.root + ',点「重新扫描」就会出现。')),
|
|
317
|
+
opened ? h('div', { style: { ...S.text, marginTop: 10 } }, (opened.title || opened.rel || '') + '\n\n' + opened.text) : null,
|
|
318
|
+
),
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
const setTabView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
322
|
+
h('div', { style: S.card },
|
|
323
|
+
h('div', { style: { fontWeight: 600, marginBottom: 8 } }, '阅读'),
|
|
324
|
+
h('div', { style: { ...S.row, marginBottom: 6 } },
|
|
325
|
+
h('div', null, '每日章节上限'), h('input', { style: S.input, type: 'number', defaultValue: (cfg && cfg.perDay) || 20, onBlur: (e) => saveCfg({ perDay: Number(e.target.value) || 0 }) }),
|
|
326
|
+
),
|
|
327
|
+
h('div', { style: { ...S.row, marginBottom: 6 } },
|
|
328
|
+
h('div', null, '每几章写一次读后感'), h('input', { style: S.input, type: 'number', defaultValue: (cfg && cfg.notesEvery) || 1, onBlur: (e) => saveCfg({ notesEvery: Number(e.target.value) || 1 }) }),
|
|
329
|
+
),
|
|
330
|
+
h('div', { style: S.row },
|
|
331
|
+
h('div', null, '静音时段(不自动读)'),
|
|
332
|
+
h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.quietFrom) || '', placeholder: '03:00', onBlur: (e) => saveCfg({ quietFrom: e.target.value }) }),
|
|
333
|
+
h('div', { style: S.dim }, '至'),
|
|
334
|
+
h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.quietTo) || '', placeholder: '08:00', onBlur: (e) => saveCfg({ quietTo: e.target.value }) }),
|
|
335
|
+
),
|
|
336
|
+
),
|
|
337
|
+
h('div', { style: S.card },
|
|
338
|
+
h('div', { style: { fontWeight: 600, marginBottom: 8 } }, '导入一本书'),
|
|
339
|
+
h('div', { style: S.row },
|
|
340
|
+
h('button', {
|
|
341
|
+
style: S.btnOn,
|
|
342
|
+
onClick: () => {
|
|
343
|
+
const el = document.getElementById('dsh-read-pick')
|
|
344
|
+
if (el) el.click()
|
|
345
|
+
},
|
|
346
|
+
}, '选择文件…'),
|
|
347
|
+
h('input', {
|
|
348
|
+
id: 'dsh-read-pick',
|
|
349
|
+
type: 'file',
|
|
350
|
+
accept: '.txt,.md,text/plain',
|
|
351
|
+
style: { display: 'none' },
|
|
352
|
+
onChange: (e) => {
|
|
353
|
+
const f = e.target.files && e.target.files[0]
|
|
354
|
+
if (!f) return
|
|
355
|
+
setMsg('读取 ' + f.name + '…')
|
|
356
|
+
const rd2 = new FileReader()
|
|
357
|
+
rd2.onload = async () => {
|
|
358
|
+
try {
|
|
359
|
+
const buf = new Uint8Array(rd2.result)
|
|
360
|
+
let bin = ''
|
|
361
|
+
const CH = 0x8000
|
|
362
|
+
for (let i = 0; i < buf.length; i += CH) {
|
|
363
|
+
bin += String.fromCharCode.apply(null, buf.subarray(i, i + CH))
|
|
364
|
+
}
|
|
365
|
+
const data = btoa(bin)
|
|
366
|
+
setMsg('导入中…')
|
|
367
|
+
const r = await fetch('/dsh-reading.importText', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ name: f.name, data }) })
|
|
368
|
+
const j = await r.json()
|
|
369
|
+
if (!j.ok) { setMsg('失败:' + (j.error || '未知')); return }
|
|
370
|
+
setMsg('已导入 ' + (j.id || '') + '(' + (j.chapters || 0) + ' 章)')
|
|
371
|
+
await load()
|
|
372
|
+
} catch (err) { setMsg('失败:' + String(err)) }
|
|
373
|
+
}
|
|
374
|
+
rd2.readAsArrayBuffer(f)
|
|
375
|
+
e.target.value = ''
|
|
376
|
+
},
|
|
377
|
+
}),
|
|
378
|
+
h('div', { style: S.dim }, '点左边选文件,或把完整路径粘在下面'),
|
|
379
|
+
),
|
|
380
|
+
h('div', { style: S.row },
|
|
381
|
+
h('input', {
|
|
382
|
+
style: { ...S.input, width: 300 },
|
|
383
|
+
placeholder: 'D:\\...\\书名.txt 或 .md',
|
|
384
|
+
onChange: (e) => { importPath = e.target.value },
|
|
385
|
+
}),
|
|
386
|
+
h('button', {
|
|
387
|
+
style: S.btnOn,
|
|
388
|
+
onClick: async () => {
|
|
389
|
+
const p = String(importPath || '').trim()
|
|
390
|
+
if (!p) { setMsg('先填文件路径'); return }
|
|
391
|
+
setMsg('导入中…')
|
|
392
|
+
try {
|
|
393
|
+
const r = await fetch('/dsh-reading.import', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: p }) })
|
|
394
|
+
const j = await r.json()
|
|
395
|
+
if (!j.ok) { setMsg('失败:' + (j.error || '未知')); return }
|
|
396
|
+
setMsg('已导入 ' + (j.id || '') + '(' + (j.chapters || 0) + ' 章)')
|
|
397
|
+
importPath = ''
|
|
398
|
+
await load()
|
|
399
|
+
} catch (e) { setMsg('失败:' + String(e)) }
|
|
400
|
+
},
|
|
401
|
+
}, '导入'),
|
|
402
|
+
),
|
|
403
|
+
h('div', { style: S.dim }, '只认 .txt / .md,会复制到书架并统计章数。'),
|
|
404
|
+
),
|
|
405
|
+
h('div', { style: S.card },
|
|
406
|
+
h('div', { style: { fontWeight: 600, marginBottom: 8 } }, '写作'),
|
|
407
|
+
h('div', { style: S.row },
|
|
408
|
+
h('div', null, '开启写作功能'),
|
|
409
|
+
h('button', { style: (cfg && cfg.writing) ? S.btnOn : S.btn, onClick: () => saveCfg({ writing: !(cfg && cfg.writing) }) }, (cfg && cfg.writing) ? '已开启' : '已关闭'),
|
|
410
|
+
h('div', { style: S.dim }, '关掉后我只读书,不写东西'),
|
|
411
|
+
),
|
|
412
|
+
),
|
|
413
|
+
h('div', { style: S.card },
|
|
414
|
+
h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
|
|
415
|
+
favs.length ? favs.map((f, i) => h('div', { key: i, style: S.row },
|
|
416
|
+
h('div', { style: { flex: 1 } }, f.replace(/^file:/, '')),
|
|
417
|
+
h('button', { style: S.btn, onClick: () => toggleFav(f) }, '取消'),
|
|
418
|
+
)) : h('div', { style: S.dim }, '在读后感或作品上点 ☆ 收藏。'),
|
|
419
|
+
),
|
|
420
|
+
h('div', { style: S.card },
|
|
421
|
+
h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '导出'),
|
|
422
|
+
h('div', { style: S.row },
|
|
423
|
+
h('button', { style: S.btn, onClick: () => { copy(raw); setMsg('读后感已复制') } }, '复制读后感全文'),
|
|
424
|
+
h('button', { style: S.btn, onClick: () => { copy(JSON.stringify(state, null, 2)); setMsg('进度已复制') } }, '复制阅读进度 JSON'),
|
|
425
|
+
),
|
|
426
|
+
h('div', { style: { ...S.dim, marginTop: 6 } }, cfg && cfg.favorites ? '' : ''),
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
return h('div', { style: S.wrap },
|
|
431
|
+
head,
|
|
432
|
+
tabs,
|
|
433
|
+
tab === 'read' ? readTab : tab === 'works' ? worksTab : setTabView,
|
|
434
|
+
)
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function Boundary(props) {
|
|
438
|
+
try { return h(Panel, props) } catch (e) {
|
|
439
|
+
return h('div', { style: { padding: 14, color: '#ff8080', fontSize: 12 } }, '半页出错了:' + String((e && e.message) || e))
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return {
|
|
444
|
+
inject: ['slots'],
|
|
445
|
+
apply(ctx) {
|
|
446
|
+
const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
|
|
447
|
+
if (!slots) return
|
|
448
|
+
slots.inject('conversation.view', () => slots.register({ name: 'conversation.view', id: 'reading', order: 42, label: '半页' }, (props) => h(Boundary, props)))
|
|
449
|
+
slots.inject('settings.section', () => slots.register({ name: 'settings.section', id: 'dsh-half-page', order: 66, label: '半页' }, () => h(Boundary)))
|
|
450
|
+
},
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
})
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" width="40" height="40" fill="none">
|
|
2
|
+
<rect x="1.5" y="1.5" width="37" height="37" rx="10" fill="#1b3a4b"/>
|
|
3
|
+
<path d="M9 12.5c3.2-1.6 6.2-1.6 8.8 0v17c-2.6-1.6-5.6-1.6-8.8 0v-17z" fill="#8fd3ff"/>
|
|
4
|
+
<path d="M31 12.5c-3.2-1.6-6.2-1.6-8.8 0v17c2.6-1.6 5.6-1.6 8.8 0v-17z" fill="#cfe9ff"/>
|
|
5
|
+
<path d="M11 15.5c1.9-.8 3.7-.8 5.4 0M11 19c1.9-.8 3.7-.8 5.4 0M11 22.5c1.9-.8 3.7-.8 5.4 0" stroke="#12303d" stroke-width="1.2" stroke-linecap="round"/>
|
|
6
|
+
<path d="M29 15.5c-1.9-.8-3.7-.8-5.4 0M29 19c-1.9-.8-3.7-.8-5.4 0" stroke="#12303d" stroke-width="1.2" stroke-linecap="round"/>
|
|
7
|
+
</svg>
|