diff --git a/web/src/reader/reader.ts b/web/src/reader/reader.ts index 0ff9d53..ad9882d 100644 --- a/web/src/reader/reader.ts +++ b/web/src/reader/reader.ts @@ -384,6 +384,7 @@ document.addEventListener("alpine:init", () => { mediaItemId: "" as string, saveTimeout: null as ReturnType | null, initTime: 0 as number, + contextText: "" as string, readingTheme: "light" as string, readingMode: "light" as string, readingFont: "literata" as string, @@ -504,6 +505,11 @@ document.addEventListener("alpine:init", () => { slider.value = fraction; slider.title = progressStr; } + const range = e.detail.range as Range | undefined; + if (range) { + const text = range.toString().replace(/\s+/g, " ").trim(); + this.contextText = text ? text.slice(0, 100) : ""; + } this.debouncedSaveProgress(fraction, location, cfi); }); const slider = document.getElementById( @@ -566,6 +572,7 @@ document.addEventListener("alpine:init", () => { }; if (!this.isFixedLayout) { body.epubcfi = cfi || ""; + body.context_text = this.contextText || ""; } const tocItem = this.lastRelocateDetail?.tocItem;