From 806836aa65e6d25aa2e5e69672d05fd25234ad58 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 16 Jul 2024 12:51:25 +0200 Subject: [PATCH 1/3] Reopen document from last position --- internal/webserver/embedded/js/foliate-js/reader.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/webserver/embedded/js/foliate-js/reader.js b/internal/webserver/embedded/js/foliate-js/reader.js index 9dc4ee6..bc4be2d 100644 --- a/internal/webserver/embedded/js/foliate-js/reader.js +++ b/internal/webserver/embedded/js/foliate-js/reader.js @@ -44,8 +44,10 @@ const getView = async file => { } if (!book) throw new Error('File type not supported') const view = document.createElement('foliate-view') + const storage = window.localStorage document.body.append(view) await view.open(book) + view.init({lastLocation: storage.getItem("loc")}) return view } @@ -222,6 +224,8 @@ class Reader { doc.addEventListener('keydown', this.#handleKeydown.bind(this)) } #onRelocate({ detail }) { + const storage = window.localStorage + storage.setItem("loc", detail.cfi) const { fraction, location, tocItem, pageItem } = detail const percent = percentFormat.format(fraction) const loc = pageItem From e6dcabf79fe0bb8a78844b88f8cedb523c799b74 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 29 Jul 2024 20:30:40 +0200 Subject: [PATCH 2/3] Fixed epub view init not resuming from last position --- .../embedded/js/{foliate-js => }/reader.js | 18 +++++++++--------- internal/webserver/embedded/views/reader.html | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) rename internal/webserver/embedded/js/{foliate-js => }/reader.js (94%) diff --git a/internal/webserver/embedded/js/foliate-js/reader.js b/internal/webserver/embedded/js/reader.js similarity index 94% rename from internal/webserver/embedded/js/foliate-js/reader.js rename to internal/webserver/embedded/js/reader.js index bc4be2d..b566ebd 100644 --- a/internal/webserver/embedded/js/foliate-js/reader.js +++ b/internal/webserver/embedded/js/reader.js @@ -1,7 +1,7 @@ -import './view.js' -import { createTOCView } from './ui/tree.js' -import { createMenu } from './ui/menu.js' -import { Overlayer } from './overlayer.js' +import './foliate-js/view.js' +import { createTOCView } from './foliate-js/ui/tree.js' +import { createMenu } from './foliate-js/ui/menu.js' +import { Overlayer } from './foliate-js/overlayer.js' const isZip = async file => { const arr = new Uint8Array(await file.slice(0, 4).arrayBuffer()) @@ -17,7 +17,7 @@ const isPDF = async file => { const makeZipLoader = async file => { const { configure, ZipReader, BlobReader, TextWriter, BlobWriter } = - await import('./vendor/zip.js') + await import('./foliate-js/vendor/zip.js') configure({ useWebWorkers: false }) const reader = new ZipReader(new BlobReader(file)) const entries = await reader.getEntries() @@ -35,11 +35,11 @@ const getView = async file => { if (!file.size) throw new Error('File not found') else if (await isZip(file)) { const loader = await makeZipLoader(file) - const { EPUB } = await import('./epub.js') + const { EPUB } = await import('./foliate-js/epub.js') book = await new EPUB(loader).init() } else if (await isPDF(file)) { - const { makePDF } = await import('./pdf.js') + const { makePDF } = await import('./foliate-js/pdf.js') book = await makePDF(file) } if (!book) throw new Error('File type not supported') @@ -47,7 +47,7 @@ const getView = async file => { const storage = window.localStorage document.body.append(view) await view.open(book) - view.init({lastLocation: storage.getItem("loc")}) + await view.init({lastLocation: storage.getItem("loc")}) return view } @@ -185,7 +185,7 @@ class Reader { // load and show highlights embedded in the file by Calibre const bookmarks = await book.getCalibreBookmarks?.() if (bookmarks) { - const { fromCalibreHighlight } = await import('./epubcfi.js') + const { fromCalibreHighlight } = await import('./foliate-js/epubcfi.js') for (const obj of bookmarks) { if (obj.type === 'highlight') { const value = fromCalibreHighlight(obj) diff --git a/internal/webserver/embedded/views/reader.html b/internal/webserver/embedded/views/reader.html index 1746b0a..3a67fb3 100644 --- a/internal/webserver/embedded/views/reader.html +++ b/internal/webserver/embedded/views/reader.html @@ -79,4 +79,4 @@ }} - + From 6d741c7daf1e585460fba17ebd127f7f342f25cc Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Thu, 1 Aug 2024 13:49:18 +0200 Subject: [PATCH 3/3] Store location per document --- internal/webserver/embedded/js/reader.js | 8 ++++++-- internal/webserver/embedded/views/reader.html | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/webserver/embedded/js/reader.js b/internal/webserver/embedded/js/reader.js index b566ebd..d292dad 100644 --- a/internal/webserver/embedded/js/reader.js +++ b/internal/webserver/embedded/js/reader.js @@ -45,9 +45,11 @@ const getView = async file => { if (!book) throw new Error('File type not supported') const view = document.createElement('foliate-view') const storage = window.localStorage + const slug = document.getElementById('slug').value + document.body.append(view) await view.open(book) - await view.init({lastLocation: storage.getItem("loc")}) + await view.init({lastLocation: storage.getItem(slug)}) return view } @@ -225,7 +227,9 @@ class Reader { } #onRelocate({ detail }) { const storage = window.localStorage - storage.setItem("loc", detail.cfi) + const slug = document.getElementById('slug').value + + storage.setItem(slug, detail.cfi) const { fraction, location, tocItem, pageItem } = detail const percent = percentFormat.format(fraction) const loc = pageItem diff --git a/internal/webserver/embedded/views/reader.html b/internal/webserver/embedded/views/reader.html index 3a67fb3..67d5daf 100644 --- a/internal/webserver/embedded/views/reader.html +++ b/internal/webserver/embedded/views/reader.html @@ -14,6 +14,7 @@ +