dsh-half-page 0.3.18 → 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.
Files changed (3) hide show
  1. package/client.js +12 -1
  2. package/index.js +28 -0
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * dsh-half-page — 半页(Client 半边)
3
3
  * 只做统计面板:读到哪、写了什么、她的作品;不显示正文(点「显示原文」才取)。
4
4
  */
5
- // 注意:下面的 id 必须等于 package.json 的 name(DSH 按入口名判重,不一致会白屏报 duplicate factory registration)
5
+ // 注意:下面的 id 必须等于 package.json 的 name(DSH 按入口名判重,不一致会白屏报 duplicate factory registration)
6
6
  window.__ModuleLoader__.load({
7
7
  id: 'dsh-half-page',
8
8
  factory(require) {
@@ -103,6 +103,16 @@ window.__ModuleLoader__.load({
103
103
  } finally { setBusy(false) }
104
104
  }
105
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
+
106
116
 
107
117
  const STATES = ['在写', '写完了', '搁下了']
108
118
  const cycleStatus = async (f) => {
@@ -210,6 +220,7 @@ window.__ModuleLoader__.load({
210
220
  h('div', { style: S.row },
211
221
  h('div', { style: { fontWeight: 600 } }, '这一本'),
212
222
  h('div', { style: { flex: 1 } }),
223
+ h('button', { style: S.btn, onClick: backOne, disabled: busy }, busy ? '…' : '退一章'),
213
224
  h('button', { style: S.btn, onClick: advance, disabled: busy }, busy ? '…' : '推进一章'),
214
225
  h('button', { style: showRaw ? S.btnOn : S.btn, onClick: async () => {
215
226
  if (!showRaw && cur) {
package/index.js CHANGED
@@ -325,6 +325,34 @@ export function apply(ctx) {
325
325
  }),
326
326
  )
327
327
 
328
+ // 面板里点「退一章」:退回上一章(手滑多点了一下能救回来)
329
+ ctx.effect(() =>
330
+ ctx.webServer.register({
331
+ kind: 'exact',
332
+ path: '/dsh-reading.back',
333
+ async handler(req, res) {
334
+ const url = new URL(req.url, 'http://x')
335
+ const { dir, st } = await stateOf()
336
+ const id = url.searchParams.get('book') || st.current
337
+ const rec = st.books[id]
338
+ res.setHeader('content-type', 'application/json; charset=utf-8')
339
+ if (!rec) return res.end(JSON.stringify({ ok: false, error: '没有这本书' }))
340
+ const cur = Number(rec.readThrough) || 0
341
+ if (cur <= 1) return res.end(JSON.stringify({ ok: false, error: '已经在第 1 章了,退不动' }))
342
+ const n = cur - 1
343
+ rec.readThrough = n
344
+ rec.next = n + 1
345
+ rec.lastReadAt = new Date().toISOString()
346
+ // 顺手把今天的计数退掉一格,免得「今天读了 21 章」虚高
347
+ const t = today()
348
+ if (st.log && st.log[t] && Number(st.log[t][id]) > 0) st.log[t][id] = Number(st.log[t][id]) - 1
349
+ await saveState(dir, st)
350
+ const info = await bookInfo(dir, id)
351
+ res.end(JSON.stringify({ ok: true, chapter: n, total: info.chapters.length }))
352
+ },
353
+ }),
354
+ )
355
+
328
356
  // 作品库:D:\dsh work\self\作品(可被 reading.config.json 的 worksDir 覆盖)
329
357
  const worksDir = async () => {
330
358
  const { dir } = await config()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",