mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-19 14:40:30 +00:00
added getCurrentFileProgress,
TODO: resolve CFI to xml node
This commit is contained in:
parent
bc65180c32
commit
b25c024b66
@ -3,10 +3,11 @@ class EpubParser {
|
||||
this.files = filesList;
|
||||
this.parser = new DOMParser();
|
||||
this.opfXml = this.getOPFXml();
|
||||
this.encoder = new TextEncoder();
|
||||
}
|
||||
|
||||
|
||||
getTextByteLength() {
|
||||
getTotalByteLength() {
|
||||
let size = 0;
|
||||
for (let key of Object.keys(this.files)) {
|
||||
let file = this.files[key];
|
||||
@ -73,10 +74,43 @@ class EpubParser {
|
||||
bytesize += this.files[filepath]._data.uncompressedSize;
|
||||
}
|
||||
} else {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bytesize;
|
||||
}
|
||||
cfiToXmlNode(file,cfi){
|
||||
|
||||
}
|
||||
/**
|
||||
takes the node that the cfi points at and counts the bytes of all nodes before that
|
||||
*/
|
||||
getCurrentFileProgress(currentFile, CFI) {
|
||||
let size = 0
|
||||
let startnode = this.cfiToXmlNode(currentFile,CFI);
|
||||
let prev = startnode.previousElementSibling;
|
||||
while (prev !== null) {
|
||||
size += this.encoder.encode(prev.outerHTML).length;
|
||||
prev = prev.previousElementSibling;
|
||||
}
|
||||
let parent = startnode.parentElement;
|
||||
while (parent !== null) {
|
||||
let parentPrev = parent.previousElementSibling;
|
||||
while (parentPrev !== null) {
|
||||
size += this.encoder.encode(parentPrev.outerHTML).length;
|
||||
parentPrev = parentPrev.previousElementSibling;
|
||||
}
|
||||
parent=parent.parentElement;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
getProgress(currentFile, CFI) {
|
||||
let percentage = this.getTotalByteLength() / (this.getPreviousFilesSize(currentFile) + this.getCurrentFileProgress(currentFile, CFI));
|
||||
if (percentage === Infinity) {
|
||||
return 0;
|
||||
} else {
|
||||
return percentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user