diff --git a/src/modules/history/HistoryModule.ts b/src/modules/history/HistoryModule.ts index 71825685..bed75012 100644 --- a/src/modules/history/HistoryModule.ts +++ b/src/modules/history/HistoryModule.ts @@ -128,26 +128,20 @@ export class HistoryModule implements ReaderModule { let lastReadingPosition = (await this.annotator.getLastReadingPosition()) as | ReadingPosition | undefined; - if ( - lastReadingPosition && - lastReadingPosition?.locations.progression && - lastReadingPosition?.locations.progression > 0 - ) { + if (lastReadingPosition) { + const linkHref = this.publication.getAbsoluteHref( + lastReadingPosition.href + ); + lastReadingPosition.href = linkHref; + if (this.historyCurrentIndex < this.history.length - 1) { this.history = this.history.slice(0, this.historyCurrentIndex); - } - lastInHistory = this.history[this.history.length - 1]; - if ( - (lastInHistory && lastInHistory.href !== lastReadingPosition.href) || - lastInHistory === undefined + this.history.push(lastReadingPosition); + this.historyCurrentIndex = this.history.length - 1; + } else if ( + lastReadingPosition?.locations.progression && + lastReadingPosition?.locations.progression > 0 ) { - const linkHref = this.publication.getAbsoluteHref( - lastReadingPosition.href - ); - log.log(lastReadingPosition.href); - log.log(linkHref); - lastReadingPosition.href = linkHref; - this.history.push(lastReadingPosition); this.historyCurrentIndex = this.history.length - 1; } diff --git a/src/modules/search/Popup.ts b/src/modules/search/Popup.ts index 6f8ece0b..8cd272e0 100644 --- a/src/modules/search/Popup.ts +++ b/src/modules/search/Popup.ts @@ -44,11 +44,10 @@ export class Popup { event.preventDefault(); event.stopPropagation(); - await fetch(absolute, this.navigator.requestConfig) - .then((r) => r.text()) - .then(async (data) => { + if (this.navigator.api?.getContent) { + await this.navigator.api?.getContent(href).then((content) => { const parser = new DOMParser(); - const doc = parser.parseFromString(data, "text/html"); + const doc = parser.parseFromString(content, "text/html"); const element = doc.querySelector("#" + id); if (element) { event.preventDefault(); @@ -56,6 +55,20 @@ export class Popup { this.showPopup(element, event); } }); + } else { + await fetch(absolute, this.navigator.requestConfig) + .then((r) => r.text()) + .then(async (data) => { + const parser = new DOMParser(); + const doc = parser.parseFromString(data, "text/html"); + const element = doc.querySelector("#" + id); + if (element) { + event.preventDefault(); + event.stopPropagation(); + this.showPopup(element, event); + } + }); + } } } } @@ -113,16 +126,25 @@ export class Popup { const d2content = document.createElement("div"); d2content.className = "d2-popover-content"; d2wrapper.appendChild(d2content); - - await fetch(absolute, this.navigator.requestConfig) - .then((r) => r.text()) - .then(async (data) => { - d2content.innerHTML = data; + if (this.navigator.api?.getContent) { + await this.navigator.api?.getContent(href).then((content) => { + d2content.innerHTML = content; let doc = this.navigator.iframes[0].contentDocument; if (doc) { doc.body.appendChild(d2popover); } }); + } else { + await fetch(absolute, this.navigator.requestConfig) + .then((r) => r.text()) + .then(async (data) => { + d2content.innerHTML = data; + let doc = this.navigator.iframes[0].contentDocument; + if (doc) { + doc.body.appendChild(d2popover); + } + }); + } let win = this.navigator.iframes[0].contentWindow; if (!win) {