Skip to content

Commit e58aaa6

Browse files
committed
Update page number in url text fragment for 1up edge case
Increase 1up mode delay for text fragment highlighting
1 parent 05e2ef2 commit e58aaa6

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/plugins/url/plugin.url.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ export class BookreaderUrlPlugin extends BookReader {
255255
if (location.includes("text=")) {
256256
this.on('textLayerVisible', async (_, {pageContainerEl}) => {
257257
const visiblePageNum = pageContainerEl.getAttribute('data-page-num');
258-
await new Promise(resolve => setTimeout(resolve, 100));
258+
let renderPageDelay = 100;
259+
if (this.mode === 1) {
260+
// maybe add some more time to have the page "settle down" from user scrolling
261+
renderPageDelay = 900;
262+
}
263+
await new Promise(resolve => setTimeout(resolve, renderPageDelay));
259264
// No textFragment found or the textFragment stored doesn't match current visible page loaded
260265
if (!this.textFragment || this.textFragmentPage !== visiblePageNum) return;
261266
if (this.options.urlMode === 'history') {

src/util/TextSelectionManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ class BRSelectMenu extends LitElement {
453453
const currentSelection = window.getSelection();
454454
/** @type {HTMLElement} */
455455
const textLayer = currentSelection.anchorNode.parentElement.closest('.BRtextLayer');
456+
// To do - updateResumeValue + getCookiePath in plugin.resume.js overrides the adjustedUrlPageNumPath, check how to workaround this
457+
const adjustedUrlPageNumPath = currentUrl.pathname.toString().replace(/(?<=\/page\/)\d+(?=\/)/, textLayer.parentElement.getAttribute('data-page-num'));
456458
if (currentParams.includes('text=')) {
457459
currentParams = currentParams.replace(/(text=)[\w\W\d%]+/, createTextFragmentUrlParam(currentSelection, textLayer));
458460
} else {
@@ -463,9 +465,9 @@ class BRSelectMenu extends LitElement {
463465
}
464466
}
465467
if (this.br.options.urlMode === 'history') {
466-
navigator.clipboard.writeText(`${currentUrl.origin}${currentUrl.pathname}${currentParams}`);
468+
navigator.clipboard.writeText(`${currentUrl.origin}${adjustedUrlPageNumPath}${currentParams}`);
467469
} else {
468-
navigator.clipboard.writeText(`${currentUrl.origin}${currentUrl.pathname}${currentParams}${currentUrl?.hash}`);
470+
navigator.clipboard.writeText(`${currentUrl.origin}${adjustedUrlPageNumPath}${currentParams}${currentUrl?.hash}`);
469471
}
470472
}
471473

0 commit comments

Comments
 (0)