mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
9a88afb370
commit
49b8fadbc2
@ -162,38 +162,37 @@ def replace_calibre_links_to_books(html):
|
|||||||
changed = False
|
changed = False
|
||||||
dom.body.querySelectorAll('a[href]').forEach(def (link):
|
dom.body.querySelectorAll('a[href]').forEach(def (link):
|
||||||
nonlocal changed
|
nonlocal changed
|
||||||
if not link.href:
|
if not link.href or not link.href.startswith('calibre://'):
|
||||||
return
|
return
|
||||||
if link.href.startswith('calibre://'):
|
url = v'new URL(link.href, window.location.origin)'
|
||||||
url = v'new URL(link.href, window.location.origin)'
|
if url.hostname is not 'show-book' and url.hostname is not 'view-book':
|
||||||
if url.hostname is not 'show-book' and url.hostname is not 'view-book':
|
return
|
||||||
return
|
path = url.pathname
|
||||||
path = url.pathname
|
parts = str.split(path, '/')
|
||||||
parts = str.split(path, '/')
|
lib, book_id = parts[1], parts[2]
|
||||||
lib, book_id = parts[1], parts[2]
|
try:
|
||||||
try:
|
book_id = int(book_id)
|
||||||
book_id = int(book_id)
|
except:
|
||||||
except:
|
return
|
||||||
return
|
if lib.startswith('_hex_-'):
|
||||||
if lib.startswith('_hex_-'):
|
lib = lib[6:]
|
||||||
lib = lib[6:]
|
v'const uint8Array = new Uint8Array(lib.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));'
|
||||||
v'const uint8Array = new Uint8Array(lib.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));'
|
v'lib = new TextDecoder("utf-8").decode(uint8Array);'
|
||||||
v'lib = new TextDecoder("utf-8").decode(uint8Array);'
|
elif lib is '_':
|
||||||
elif lib is '_':
|
lib = current_library_id()
|
||||||
lib = current_library_id()
|
if url.hostname is 'show-book':
|
||||||
if url.hostname is 'show-book':
|
new_href = query_as_href({'book_id': book_id + '', 'library_id': lib}, 'book_details')
|
||||||
new_href = query_as_href({'book_id': book_id + '', 'library_id': lib}, 'book_details')
|
else:
|
||||||
else:
|
fmt = parts[3]
|
||||||
fmt = parts[3]
|
extra_query = {}
|
||||||
extra_query = {}
|
url.searchParams.forEach(def(val, key):
|
||||||
url.searchParams.forEach(def(val, key):
|
extra_query[key] = val
|
||||||
extra_query[key] = val
|
)
|
||||||
)
|
new_href = open_book_url_in_library(lib, book_id, fmt, extra_query)
|
||||||
new_href = open_book_url_in_library(lib, book_id, fmt, extra_query)
|
if url.search:
|
||||||
if url.search:
|
new_href
|
||||||
new_href
|
link.href = new_href
|
||||||
link.href = new_href
|
changed = True
|
||||||
changed = True
|
|
||||||
)
|
)
|
||||||
if changed:
|
if changed:
|
||||||
return v'new XMLSerializer().serializeToString(dom);'
|
return v'new XMLSerializer().serializeToString(dom);'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user