feat(reader): wire up reading progress save and restore
The web reader had all the infrastructure for progress persistence
(updateReadingProgress/getReadingProgress API functions, PUT/GET
endpoints, database queries) but the reader.ts never called them.
Changes:
- Add debounced (2s) saveProgress call on every relocate event that
PUTs percentage, current_page, total_pages, and epubcfi to the
existing /api/media-items/:id/progress endpoint
- Replace renderer.next() with view.init({ lastLocation }) to restore
the reader to the last saved position on load (CFI first, then
fraction fallback, then default first page)
- Pass savedPercentage and savedCfi from server-side progress data
through readerInitExpr config to the JS initReader function
- Add mediaItemId and saveTimeout to the Alpine data object
This fixes both the blank /progress page and the missing progress
section on book detail pages — both were empty because the
reading_progress table never received any data from the web reader.
This commit is contained in:
@@ -5,14 +5,20 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func readerInitExpr(metadata ReaderMetadata) string {
|
||||
config := map[string]string{
|
||||
func readerInitExpr(metadata ReaderMetadata, progress ReadingProgress) string {
|
||||
config := map[string]interface{}{
|
||||
"mediaItemId": metadata.MediaItemID,
|
||||
"fileUrl": metadata.FileURL,
|
||||
"formatGroup": metadata.FormatGroup,
|
||||
"readingDirection": metadata.ReadingDirection,
|
||||
"mangaType": metadata.MangaType,
|
||||
}
|
||||
if progress.Percentage > 0 {
|
||||
config["savedPercentage"] = progress.Percentage
|
||||
}
|
||||
if progress.EpubCfi != "" {
|
||||
config["savedCfi"] = progress.EpubCfi
|
||||
}
|
||||
jsonBytes, _ := json.Marshal(config)
|
||||
return fmt.Sprintf("initReader(%s)", string(jsonBytes))
|
||||
}
|
||||
@@ -32,7 +38,7 @@ templ Reader(user User, metadata ReaderMetadata, progress ReadingProgress, bookm
|
||||
</head>
|
||||
<body
|
||||
x-data="readerShell"
|
||||
x-init={ readerInitExpr(metadata) }
|
||||
x-init={ readerInitExpr(metadata, progress) }
|
||||
class="theme-tokyo-night h-screen overflow-hidden"
|
||||
>
|
||||
@ReaderChrome(user, metadata, progress)
|
||||
|
||||
+17
-11
@@ -13,14 +13,20 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func readerInitExpr(metadata ReaderMetadata) string {
|
||||
config := map[string]string{
|
||||
func readerInitExpr(metadata ReaderMetadata, progress ReadingProgress) string {
|
||||
config := map[string]interface{}{
|
||||
"mediaItemId": metadata.MediaItemID,
|
||||
"fileUrl": metadata.FileURL,
|
||||
"formatGroup": metadata.FormatGroup,
|
||||
"readingDirection": metadata.ReadingDirection,
|
||||
"mangaType": metadata.MangaType,
|
||||
}
|
||||
if progress.Percentage > 0 {
|
||||
config["savedPercentage"] = progress.Percentage
|
||||
}
|
||||
if progress.EpubCfi != "" {
|
||||
config["savedCfi"] = progress.EpubCfi
|
||||
}
|
||||
jsonBytes, _ := json.Marshal(config)
|
||||
return fmt.Sprintf("initReader(%s)", string(jsonBytes))
|
||||
}
|
||||
@@ -53,7 +59,7 @@ func Reader(user User, metadata ReaderMetadata, progress ReadingProgress, bookma
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(metadata.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 26, Col: 26}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 32, Col: 26}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -64,9 +70,9 @@ func Reader(user User, metadata ReaderMetadata, progress ReadingProgress, bookma
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(readerInitExpr(metadata))
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(readerInitExpr(metadata, progress))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 35, Col: 36}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 41, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -156,7 +162,7 @@ func ReaderChrome(user User, metadata ReaderMetadata, progress ReadingProgress)
|
||||
var templ_7745c5c3_Var5 templ.SafeURL
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinURLErrs("/media/" + metadata.MediaItemID)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 73, Col: 46}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 79, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -169,7 +175,7 @@ func ReaderChrome(user User, metadata ReaderMetadata, progress ReadingProgress)
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(metadata.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 76, Col: 54}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 82, Col: 54}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -182,7 +188,7 @@ func ReaderChrome(user User, metadata ReaderMetadata, progress ReadingProgress)
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d/%d", progress.CurrentPage, progress.TotalPages))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 152, Col: 70}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 158, Col: 70}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -321,7 +327,7 @@ func ReaderBookmarksPanel(bookmarks []Bookmark) templ.Component {
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(bookmark.CfiPosition)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 368, Col: 38}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 374, Col: 38}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -334,7 +340,7 @@ func ReaderBookmarksPanel(bookmarks []Bookmark) templ.Component {
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(bookmark.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 371, Col: 49}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 377, Col: 49}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -347,7 +353,7 @@ func ReaderBookmarksPanel(bookmarks []Bookmark) templ.Component {
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(bookmark.Position)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 373, Col: 27}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/reader.templ`, Line: 379, Col: 27}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
+189
-31
@@ -22,28 +22,138 @@ interface FontFile {
|
||||
}
|
||||
|
||||
const FONT_FILES: FontFile[] = [
|
||||
{ family: '"Literata"', url: "/static/fonts/literata/Literata-Variable.woff2", weight: "100 900", style: "normal" },
|
||||
{ family: '"Literata"', url: "/static/fonts/literata/Literata-Italic-Variable.woff2", weight: "100 900", style: "italic" },
|
||||
{ family: '"Crimson Pro"', url: "/static/fonts/crimson/CrimsonPro-Variable.woff2", weight: "100 900", style: "normal" },
|
||||
{ family: '"Crimson Pro"', url: "/static/fonts/crimson/CrimsonPro-Italic-Variable.woff2", weight: "100 900", style: "italic" },
|
||||
{ family: '"Source Serif 4"', url: "/static/fonts/source-serif/SourceSerif4-Variable.woff2", weight: "100 900", style: "normal" },
|
||||
{ family: '"Source Serif 4"', url: "/static/fonts/source-serif/SourceSerif4-Italic-Variable.woff2", weight: "100 900", style: "italic" },
|
||||
{ family: '"EB Garamond"', url: "/static/fonts/eb-garamond/EBGaramond-Variable.woff2", weight: "100 900", style: "normal" },
|
||||
{ family: '"EB Garamond"', url: "/static/fonts/eb-garamond/EBGaramond-Italic-Variable.woff2", weight: "100 900", style: "italic" },
|
||||
{ family: '"Libertinus Serif"', url: "/static/fonts/libertinus/LibertinusSerif-Regular.woff2", weight: "400", style: "normal" },
|
||||
{ family: '"Libertinus Serif"', url: "/static/fonts/libertinus/LibertinusSerif-Bold.woff2", weight: "700", style: "normal" },
|
||||
{ family: '"Libertinus Serif"', url: "/static/fonts/libertinus/LibertinusSerif-Italic.woff2", weight: "400", style: "italic" },
|
||||
{ family: '"Libertinus Serif"', url: "/static/fonts/libertinus/LibertinusSerif-BoldItalic.woff2", weight: "700", style: "italic" },
|
||||
{ family: '"Noto Serif"', url: "/static/fonts/noto-serif/NotoSerif-Variable.woff2", weight: "100 900", style: "normal" },
|
||||
{ family: '"Noto Serif"', url: "/static/fonts/noto-serif/NotoSerif-Italic-Variable.woff2", weight: "100 900", style: "italic" },
|
||||
{ family: '"Charis SIL"', url: "/static/fonts/charis-sil/CharisSIL-Regular.woff2", weight: "400", style: "normal" },
|
||||
{ family: '"Charis SIL"', url: "/static/fonts/charis-sil/CharisSIL-Bold.woff2", weight: "700", style: "normal" },
|
||||
{ family: '"Charis SIL"', url: "/static/fonts/charis-sil/CharisSIL-Italic.woff2", weight: "400", style: "italic" },
|
||||
{ family: '"Charis SIL"', url: "/static/fonts/charis-sil/CharisSIL-BoldItalic.woff2", weight: "700", style: "italic" },
|
||||
{ family: '"IBM Plex Serif"', url: "/static/fonts/ibm-plex/IBMPlexSerif-Regular.woff2", weight: "400", style: "normal" },
|
||||
{ family: '"IBM Plex Serif"', url: "/static/fonts/ibm-plex/IBMPlexSerif-Bold.woff2", weight: "700", style: "normal" },
|
||||
{ family: '"IBM Plex Serif"', url: "/static/fonts/ibm-plex/IBMPlexSerif-Italic.woff2", weight: "400", style: "italic" },
|
||||
{ family: '"IBM Plex Serif"', url: "/static/fonts/ibm-plex/IBMPlexSerif-BoldItalic.woff2", weight: "700", style: "italic" },
|
||||
{
|
||||
family: '"Literata"',
|
||||
url: "/static/fonts/literata/Literata-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Literata"',
|
||||
url: "/static/fonts/literata/Literata-Italic-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Crimson Pro"',
|
||||
url: "/static/fonts/crimson/CrimsonPro-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Crimson Pro"',
|
||||
url: "/static/fonts/crimson/CrimsonPro-Italic-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Source Serif 4"',
|
||||
url: "/static/fonts/source-serif/SourceSerif4-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Source Serif 4"',
|
||||
url: "/static/fonts/source-serif/SourceSerif4-Italic-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"EB Garamond"',
|
||||
url: "/static/fonts/eb-garamond/EBGaramond-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"EB Garamond"',
|
||||
url: "/static/fonts/eb-garamond/EBGaramond-Italic-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Libertinus Serif"',
|
||||
url: "/static/fonts/libertinus/LibertinusSerif-Regular.woff2",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Libertinus Serif"',
|
||||
url: "/static/fonts/libertinus/LibertinusSerif-Bold.woff2",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Libertinus Serif"',
|
||||
url: "/static/fonts/libertinus/LibertinusSerif-Italic.woff2",
|
||||
weight: "400",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Libertinus Serif"',
|
||||
url: "/static/fonts/libertinus/LibertinusSerif-BoldItalic.woff2",
|
||||
weight: "700",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Noto Serif"',
|
||||
url: "/static/fonts/noto-serif/NotoSerif-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Noto Serif"',
|
||||
url: "/static/fonts/noto-serif/NotoSerif-Italic-Variable.woff2",
|
||||
weight: "100 900",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Charis SIL"',
|
||||
url: "/static/fonts/charis-sil/CharisSIL-Regular.woff2",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Charis SIL"',
|
||||
url: "/static/fonts/charis-sil/CharisSIL-Bold.woff2",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"Charis SIL"',
|
||||
url: "/static/fonts/charis-sil/CharisSIL-Italic.woff2",
|
||||
weight: "400",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"Charis SIL"',
|
||||
url: "/static/fonts/charis-sil/CharisSIL-BoldItalic.woff2",
|
||||
weight: "700",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"IBM Plex Serif"',
|
||||
url: "/static/fonts/ibm-plex/IBMPlexSerif-Regular.woff2",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"IBM Plex Serif"',
|
||||
url: "/static/fonts/ibm-plex/IBMPlexSerif-Bold.woff2",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
family: '"IBM Plex Serif"',
|
||||
url: "/static/fonts/ibm-plex/IBMPlexSerif-Italic.woff2",
|
||||
weight: "400",
|
||||
style: "italic",
|
||||
},
|
||||
{
|
||||
family: '"IBM Plex Serif"',
|
||||
url: "/static/fonts/ibm-plex/IBMPlexSerif-BoldItalic.woff2",
|
||||
weight: "700",
|
||||
style: "italic",
|
||||
},
|
||||
];
|
||||
|
||||
let fontBlobUrls: Record<string, string> = {};
|
||||
@@ -87,7 +197,8 @@ interface ThemeColors {
|
||||
link: string;
|
||||
}
|
||||
|
||||
const THEME_COLORS: Record<string, { light: ThemeColors; dark: ThemeColors }> = {
|
||||
const THEME_COLORS: Record<string, { light: ThemeColors; dark: ThemeColors }> =
|
||||
{
|
||||
light: {
|
||||
light: { fg: "#1a1a1a", bg: "#fafafa", link: "#0066cc" },
|
||||
dark: { fg: "#e8e8e8", bg: "#1a1a1a", link: "#60a5fa" },
|
||||
@@ -182,13 +293,15 @@ const getCSS = ({
|
||||
const themeSet = THEME_COLORS[themeName] ?? THEME_COLORS.light;
|
||||
const theme = themeMode === "dark" ? themeSet.dark : themeSet.light;
|
||||
const font = FONT_MAP[fontFamily] ?? '"Literata"';
|
||||
const fontFamilyRule = fontFamily ? `
|
||||
const fontFamilyRule = fontFamily
|
||||
? `
|
||||
body {
|
||||
font-family: ${font}, serif !important;
|
||||
}
|
||||
body * {
|
||||
font-family: inherit !important;
|
||||
}` : "";
|
||||
}`
|
||||
: "";
|
||||
|
||||
return `
|
||||
${buildFontFaceCSS()}
|
||||
@@ -265,6 +378,8 @@ document.addEventListener("alpine:init", () => {
|
||||
bookmarksOpen: false,
|
||||
navigatorOpen: false,
|
||||
tocItems: [] as any[],
|
||||
mediaItemId: "" as string,
|
||||
saveTimeout: null as ReturnType<typeof setTimeout> | null,
|
||||
readingTheme: "light" as string,
|
||||
readingMode: "light" as string,
|
||||
readingFont: "literata" as string,
|
||||
@@ -276,7 +391,10 @@ document.addEventListener("alpine:init", () => {
|
||||
formatGroup: string;
|
||||
readingDirection: string;
|
||||
mangaType: string;
|
||||
savedPercentage?: number;
|
||||
savedCfi?: string;
|
||||
}) {
|
||||
this.mediaItemId = config.mediaItemId;
|
||||
this.settings = await loadSettings();
|
||||
if (this.settings) {
|
||||
this.readingTheme = this.settings.reading_theme || "light";
|
||||
@@ -291,7 +409,8 @@ document.addEventListener("alpine:init", () => {
|
||||
}
|
||||
const viewport = document.getElementById("reader-viewport")!;
|
||||
const themeSet = THEME_COLORS[this.readingTheme] ?? THEME_COLORS.light;
|
||||
const themeColors = this.readingMode === "dark" ? themeSet.dark : themeSet.light;
|
||||
const themeColors =
|
||||
this.readingMode === "dark" ? themeSet.dark : themeSet.light;
|
||||
viewport.style.backgroundColor = themeColors.bg;
|
||||
this.view = document.getElementById("reader-view") as any;
|
||||
await loadFontBlobUrls();
|
||||
@@ -324,7 +443,7 @@ document.addEventListener("alpine:init", () => {
|
||||
);
|
||||
});
|
||||
this.view.addEventListener("relocate", (e: any) => {
|
||||
const { fraction, location, pageItem } = e.detail;
|
||||
const { fraction, location, pageItem, cfi } = e.detail;
|
||||
const percent = new Intl.NumberFormat("en", {
|
||||
style: "percent",
|
||||
}).format(fraction);
|
||||
@@ -340,6 +459,7 @@ document.addEventListener("alpine:init", () => {
|
||||
slider.value = fraction;
|
||||
slider.title = `${percent} · ${loc}`;
|
||||
}
|
||||
this.debouncedSaveProgress(fraction, location, cfi);
|
||||
});
|
||||
const slider = document.getElementById(
|
||||
"progress-slider",
|
||||
@@ -360,7 +480,40 @@ document.addEventListener("alpine:init", () => {
|
||||
document.addEventListener("keydown", (ev: KeyboardEvent) =>
|
||||
this.handleKeydown(ev),
|
||||
);
|
||||
this.renderer.next();
|
||||
if (config.savedCfi) {
|
||||
await this.view.init({ lastLocation: config.savedCfi });
|
||||
} else if (config.savedPercentage && config.savedPercentage > 0) {
|
||||
await this.view.init({ lastLocation: { fraction: config.savedPercentage } });
|
||||
} else {
|
||||
await this.view.init({});
|
||||
}
|
||||
},
|
||||
debouncedSaveProgress(fraction: number, location: any, cfi: string) {
|
||||
if (this.saveTimeout) clearTimeout(this.saveTimeout);
|
||||
this.saveTimeout = setTimeout(() => {
|
||||
this.saveProgress(fraction, location, cfi);
|
||||
}, 2000);
|
||||
},
|
||||
async saveProgress(fraction: number, location: any, cfi: string) {
|
||||
const token = getToken();
|
||||
if (!token || !this.mediaItemId) return;
|
||||
try {
|
||||
await fetch(`/api/media-items/${this.mediaItemId}/progress`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
percentage: fraction,
|
||||
current_page: location?.current ?? 0,
|
||||
total_pages: location?.total ?? 0,
|
||||
epubcfi: cfi || "",
|
||||
}),
|
||||
});
|
||||
} catch (_e) {
|
||||
// silent fail — progress save is non-critical
|
||||
}
|
||||
},
|
||||
zoomIn() {
|
||||
if (!this.isFixedLayout) return;
|
||||
@@ -451,7 +604,8 @@ document.addEventListener("alpine:init", () => {
|
||||
applyTheme() {
|
||||
const viewport = document.getElementById("reader-viewport")!;
|
||||
const themeSet = THEME_COLORS[this.readingTheme] ?? THEME_COLORS.light;
|
||||
const themeColors = this.readingMode === "dark" ? themeSet.dark : themeSet.light;
|
||||
const themeColors =
|
||||
this.readingMode === "dark" ? themeSet.dark : themeSet.light;
|
||||
viewport.style.backgroundColor = themeColors.bg;
|
||||
this.applyStyles();
|
||||
saveSettings({
|
||||
@@ -465,8 +619,12 @@ document.addEventListener("alpine:init", () => {
|
||||
},
|
||||
detectChromeDarkMode(): boolean {
|
||||
const darkChromeThemes = [
|
||||
"theme-tokyo-night", "theme-dracula", "theme-nord",
|
||||
"theme-monokai", "theme-one-dark", "theme-material",
|
||||
"theme-tokyo-night",
|
||||
"theme-dracula",
|
||||
"theme-nord",
|
||||
"theme-monokai",
|
||||
"theme-one-dark",
|
||||
"theme-material",
|
||||
"theme-catppuccin",
|
||||
];
|
||||
return darkChromeThemes.some((t) => document.body.classList.contains(t));
|
||||
|
||||
Reference in New Issue
Block a user