From 78914aef4466eb960965702401634c2cb348e9b1 Mon Sep 17 00:00:00 2001 From: Francesco Martini Date: Fri, 1 May 2026 21:24:25 +0200 Subject: [PATCH] Use original hrefs for external links and add isExternal in fb2.js (#129) --- fb2.js | 1 + view.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fb2.js b/fb2.js index ce9bdc0..74784ad 100644 --- a/fb2.js +++ b/fb2.js @@ -351,6 +351,7 @@ export const makeFB2 = async blob => { } book.splitTOCHref = href => href?.split('#')?.map(x => Number(x)) ?? [] book.getTOCFragment = (doc, id) => doc.querySelector(`[${dataID}="${id}"]`) + book.isExternal = uri => /^\w+:/i.test(uri) book.destroy = () => { for (const url of urls) URL.revokeObjectURL(url) diff --git a/view.js b/view.js index 7397ea2..9bdaf02 100644 --- a/view.js +++ b/view.js @@ -357,8 +357,8 @@ export class View extends HTMLElement { const href_ = a.getAttribute('href') const href = section?.resolveHref?.(href_) ?? href_ if (book?.isExternal?.(href)) - Promise.resolve(this.#emit('external-link', { a, href }, true)) - .then(x => x ? globalThis.open(href, '_blank') : null) + Promise.resolve(this.#emit('external-link', { a, href_ }, true)) + .then(x => x ? globalThis.open(href_, '_blank') : null) .catch(e => console.error(e)) else Promise.resolve(this.#emit('link', { a, href }, true)) .then(x => x ? this.goTo(href) : null)