-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.js
More file actions
39 lines (33 loc) · 1.19 KB
/
reader.js
File metadata and controls
39 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const bookPath = window.readerAPI.getBookPath();
console.log("Book path:", bookPath);
const readerDiv = document.getElementById('reader');
window.readerAPI.getBookBuffer(bookPath)
.then((arrayBuffer) => {
console.log("Buffer loaded:", arrayBuffer.byteLength);
const book = ePub(arrayBuffer);
const rendition = book.renderTo(readerDiv, {
width: "100%",
height: "100%",
allowScriptedContent: true
});
rendition.hooks.content.register((contents) => {
// Unsandbox iframe
const frame = contents.document.defaultView?.frameElement;
if (frame && frame.hasAttribute('sandbox')) {
frame.removeAttribute('sandbox');
console.log("Removed sandbox from iframe");
}
// Remove all <script> tags inside book content
const scripts = contents.document.querySelectorAll("script");
scripts.forEach((script) => {
console.warn("Stripped <script> from book:", script.outerHTML);
script.remove();
});
});
rendition.display().then(() => {
console.log("Book displayed");
});
})
.catch(err => {
console.error("Error loading or displaying book:", err);
});