Fix PDF position restore: timer after restore, add scroll-mode case
- Move auto-save timer setup to after position restore so an early visibilitychange can't overwrite the saved position with 0 - Add missing restore path for non-paginated PDF scroll mode Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
68bb7b5920
commit
1bda59e3fc
1 changed files with 9 additions and 3 deletions
|
|
@ -3157,7 +3157,7 @@ async function openBook(bookId) {
|
|||
progressInput.addEventListener('click', function () { this.select(); });
|
||||
}
|
||||
|
||||
// Restore scroll position
|
||||
// Restore scroll position — must happen BEFORE auto-save timer is started
|
||||
try {
|
||||
const progressRes = await fetch('/books/');
|
||||
const allBooks = await progressRes.json();
|
||||
|
|
@ -3169,8 +3169,13 @@ async function openBook(bookId) {
|
|||
if (fraction > 0 && pdfTotalPages > 1)
|
||||
pdfCurrentPage = Math.max(1, Math.round(fraction * (pdfTotalPages - 1)) + 1);
|
||||
enterPdfPaginatedMode();
|
||||
} else if (!isPdf) {
|
||||
// Wait for all images so scrollHeight is final
|
||||
} else if (isPdf) {
|
||||
// PDF scroll mode
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
if (fraction > 0)
|
||||
contentEl.scrollTop = fraction * (contentEl.scrollHeight - contentEl.clientHeight);
|
||||
} else {
|
||||
// EPUB — wait for images so scrollHeight is final
|
||||
const imgs = Array.from(contentEl.querySelectorAll('img'));
|
||||
if (imgs.length) {
|
||||
await Promise.all(imgs.map(img =>
|
||||
|
|
@ -3206,6 +3211,7 @@ async function openBook(bookId) {
|
|||
});
|
||||
|
||||
// Auto-save progress every 10s and on scroll (debounced 2s)
|
||||
// Started AFTER restore so an early visibilitychange can't overwrite with position 0
|
||||
readerScrollSaveTimer = setInterval(saveReaderProgress, 10000);
|
||||
let _scrollDebounce = null;
|
||||
contentEl.addEventListener('scroll', () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue