EpubParser now gets automatically loaded
TODO:detect page change, display number
This commit is contained in:
parent
dbac685985
commit
cbaa61bbb7
|
@ -12,7 +12,7 @@ class EpubParser {
|
||||||
for (let key of Object.keys(this.files)) {
|
for (let key of Object.keys(this.files)) {
|
||||||
let file = this.files[key];
|
let file = this.files[key];
|
||||||
if (file.name.endsWith("html")) {
|
if (file.name.endsWith("html")) {
|
||||||
console.log(file.name + " " + file._data.uncompressedSize)
|
// console.log(file.name + " " + file._data.uncompressedSize)
|
||||||
size += file._data.uncompressedSize;
|
size += file._data.uncompressedSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ class EpubParser {
|
||||||
let filepath = this.resolveIDref(file);
|
let filepath = this.resolveIDref(file);
|
||||||
//ignore non text files
|
//ignore non text files
|
||||||
if (filepath.endsWith("html")) {
|
if (filepath.endsWith("html")) {
|
||||||
console.log(filepath + " " + bytesize)
|
// console.log(filepath + " " + bytesize)
|
||||||
bytesize += this.files[filepath]._data.uncompressedSize;
|
bytesize += this.files[filepath]._data.uncompressedSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,8 +94,8 @@ class EpubParser {
|
||||||
let currentNode = xml.getElementsByTagName("html")[0];
|
let currentNode = xml.getElementsByTagName("html")[0];
|
||||||
for (const component of components) {
|
for (const component of components) {
|
||||||
this.validateChildNodes(currentNode);
|
this.validateChildNodes(currentNode);
|
||||||
console.log(currentNode);
|
// console.log(currentNode);
|
||||||
console.log(component);
|
// console.log(component);
|
||||||
let index = 0;
|
let index = 0;
|
||||||
if (component.includes("[")) {
|
if (component.includes("[")) {
|
||||||
index = parseInt(component.split("[")[0]) - 1;
|
index = parseInt(component.split("[")[0]) - 1;
|
||||||
|
@ -140,9 +140,9 @@ class EpubParser {
|
||||||
let xmlnsLength = startnode.parentNode.namespaceURI.length;
|
let xmlnsLength = startnode.parentNode.namespaceURI.length;
|
||||||
let prev = startnode.parentNode.previousElementSibling;
|
let prev = startnode.parentNode.previousElementSibling;
|
||||||
while (prev !== null) {
|
while (prev !== null) {
|
||||||
console.log("size: "+size)
|
// console.log("size: "+size)
|
||||||
console.log(prev.outerHTML)
|
// console.log(prev.outerHTML)
|
||||||
console.log(this.encoder.encode(prev.outerHTML).length - xmlnsLength)
|
// console.log(this.encoder.encode(prev.outerHTML).length - xmlnsLength)
|
||||||
size += this.encoder.encode(prev.outerHTML).length - xmlnsLength;
|
size += this.encoder.encode(prev.outerHTML).length - xmlnsLength;
|
||||||
prev = prev.previousElementSibling;
|
prev = prev.previousElementSibling;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,8 @@ class EpubParser {
|
||||||
while (parent !== null) {
|
while (parent !== null) {
|
||||||
let parentPrev = parent.previousElementSibling;
|
let parentPrev = parent.previousElementSibling;
|
||||||
while (parentPrev !== null) {
|
while (parentPrev !== null) {
|
||||||
console.log(parentPrev.outerHTML)
|
// console.log(parentPrev.outerHTML)
|
||||||
console.log(this.encoder.encode(parentPrev.outerHTML).length - xmlnsLength)
|
// console.log(this.encoder.encode(parentPrev.outerHTML).length - xmlnsLength)
|
||||||
|
|
||||||
size += this.encoder.encode(parentPrev.outerHTML).length - xmlnsLength;
|
size += this.encoder.encode(parentPrev.outerHTML).length - xmlnsLength;
|
||||||
parentPrev = parentPrev.previousElementSibling;
|
parentPrev = parentPrev.previousElementSibling;
|
||||||
|
@ -162,7 +162,7 @@ class EpubParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
getProgress(currentFile, CFI) {
|
getProgress(currentFile, CFI) {
|
||||||
let percentage = this.getTotalByteLength() / (this.getPreviousFilesSize(currentFile) + this.getCurrentFileProgress(CFI));
|
let percentage = (this.getPreviousFilesSize(currentFile) + this.getCurrentFileProgress(CFI))/this.getTotalByteLength();
|
||||||
if (percentage === Infinity) {
|
if (percentage === Infinity) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,5 +170,30 @@ class EpubParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function waitFor(variable, callback) {
|
||||||
|
var interval = setInterval(function() {
|
||||||
|
if (variable!==undefined) {
|
||||||
|
clearInterval(interval);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
e = new EpubParser(reader.book.archive.zip.files)
|
/**
|
||||||
|
* returns progress percentage
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
function calculateProgress(){
|
||||||
|
let data=reader.rendition.currentLocation().end;
|
||||||
|
return epubParser.getProgress(epubParser.absPath(data.href),data.cfi).toFixed(2)*100;
|
||||||
|
}
|
||||||
|
var epubParser;
|
||||||
|
waitFor(reader.book,()=>{
|
||||||
|
epubParser = new EpubParser(reader.book.archive.zip.files);
|
||||||
|
})
|
||||||
|
|
||||||
|
window.addEventListener('hashchange',()=>{console.log("test")})
|
||||||
|
/*
|
||||||
|
document.getElementById("next").addEventListener('click',calculateProgress);
|
||||||
|
document.getElementById("prev").addEventListener('click',calculateProgress);
|
||||||
|
*/
|
||||||
|
|
|
@ -104,8 +104,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="overlay"></div>
|
<div class="overlay"></div>
|
||||||
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/compress/jszip_epub.min.js') }}">
|
<script src="{{ url_for('static', filename='js/compress/jszip_epub.min.js') }}"></script>
|
||||||
</script>
|
|
||||||
<script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.calibre = {
|
window.calibre = {
|
||||||
|
@ -153,19 +152,7 @@
|
||||||
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/reader.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/reader.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/reading/epub.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/reading/epub.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/pako.min.js') }}"</script>
|
<script src="{{ url_for('static', filename='js/reading/epub-progress.js') }}"></script>
|
||||||
<script>
|
<script src="{{ url_for('static', filename='js/libs/pako.min.js') }}"></script>
|
||||||
function getTextByteLength() {
|
|
||||||
let size = 0;
|
|
||||||
const files = reader.rendition.book.archive.zip.files;
|
|
||||||
for (let key in y = Object.keys(files)) {
|
|
||||||
let file = files[y[key]];
|
|
||||||
if (file.name.endsWith(".html")) {
|
|
||||||
size += file._data.uncompressedSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user