From 03475e1880537a2fcb0add14a6785a084e3e2b20 Mon Sep 17 00:00:00 2001 From: naiy Date: Fri, 31 Jul 2026 04:09:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=98=8E=E7=A1=AE=20hook=20callback=20?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0=E7=AD=BE=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ts | 2 +- src/hooks/index.ts | 2 ++ src/hooks/readerHook.ts | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index c02c4fc..6d2601f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ export interface HookConfig { query: URLSearchParams, hash: string ) => boolean; - handler: Function; + handler: (previous?: string) => Promise; } /* diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 9eaddd6..b94ecb8 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -2,11 +2,13 @@ import type { HookConfig, HookEvent } from "../config"; import readerHook from "./readerHook"; import fetchHook from "./fetchHook"; import userHook from "./userHook"; +import bookshelfHook from "./bookshelfHook"; const hooks: HookConfig[] = [ ...readerHook, ...fetchHook, ...userHook, + ...bookshelfHook, ]; async function onEvent(event: HookEvent, previous?: string) { diff --git a/src/hooks/readerHook.ts b/src/hooks/readerHook.ts index 7bdc8a8..12d5fd8 100644 --- a/src/hooks/readerHook.ts +++ b/src/hooks/readerHook.ts @@ -282,11 +282,11 @@ async function insertContent() { } // let currentBook: Book | null = null -async function onUrlChange(_previous: string): Promise { +async function onUrlChange(_previous?: string): Promise { // TODO: 记录并上报阅读历史和记录 await insertContent() } -async function onHashChange(_previous: string): Promise { +async function onHashChange(_previous?: string): Promise { // TODO: 支持从hash里解析并跳转到指定行 } async function onLoad(): Promise {