mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-06-12 09:54:38 -04:00
fix bug
Former-commit-id: 82d993f035d931c329a6111bbfff53e0231b0562
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -83,7 +83,7 @@ class TextToSpeech extends React.Component<
|
||||
if (StorageUtil.getReaderConfig("isSliding") === "yes") {
|
||||
await sleep(1000);
|
||||
}
|
||||
text = await this.props.htmlBook.rendition.visibleText();
|
||||
text = this.props.htmlBook.rendition.visibleText();
|
||||
text = text
|
||||
.replace(/\s\s/g, "")
|
||||
.replace(/\r/g, "")
|
||||
|
||||
@@ -163,7 +163,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
this.props.currentBook.key,
|
||||
this.state.readerMode
|
||||
);
|
||||
let chapters = await rendition.getChapter();
|
||||
let chapters = rendition.getChapter();
|
||||
let flattenChapters = rendition.flatChapter(chapters);
|
||||
this.props.handleHtmlBook({
|
||||
key: this.props.currentBook.key,
|
||||
@@ -206,8 +206,8 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
})
|
||||
);
|
||||
|
||||
rendition.on("rendered", async () => {
|
||||
await this.handleLocation();
|
||||
rendition.on("rendered", () => {
|
||||
this.handleLocation();
|
||||
let bookLocation: {
|
||||
text: string;
|
||||
count: string;
|
||||
@@ -264,8 +264,8 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
handleLocation = async () => {
|
||||
let position = await this.props.htmlBook.rendition.getPosition();
|
||||
handleLocation = () => {
|
||||
let position = this.props.htmlBook.rendition.getPosition();
|
||||
RecordLocation.recordHtmlLocation(
|
||||
this.props.currentBook.key,
|
||||
position.text,
|
||||
@@ -321,7 +321,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
document.getElementsByClassName("html-viewer-page")[0],
|
||||
parseInt(bookLocation.count) || 0
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
handleMobi = async (result: ArrayBuffer) => {
|
||||
let rendition = new MobiRender(
|
||||
@@ -332,7 +332,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
handleEpub = async (result: ArrayBuffer) => {
|
||||
let rendition = new EpubRender(
|
||||
@@ -353,7 +353,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
document.getElementsByClassName("html-viewer-page")[0],
|
||||
bookLocation.cfi
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
handleTxt = async (result: ArrayBuffer) => {
|
||||
const array = new Uint8Array(result as ArrayBuffer);
|
||||
@@ -374,7 +374,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
handleMD = (result: ArrayBuffer) => {
|
||||
var blob = new Blob([result], { type: "text/plain" });
|
||||
@@ -389,7 +389,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
reader.readAsText(blob, "UTF-8");
|
||||
};
|
||||
@@ -416,7 +416,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -432,7 +432,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
});
|
||||
};
|
||||
handleFb2 = async (result: ArrayBuffer) => {
|
||||
@@ -444,7 +444,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
handleHtml = (result: ArrayBuffer, format: string) => {
|
||||
var blob = new Blob([result], {
|
||||
@@ -461,7 +461,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
await rendition.renderTo(
|
||||
document.getElementsByClassName("html-viewer-page")[0]
|
||||
);
|
||||
this.handleRest(rendition);
|
||||
await this.handleRest(rendition);
|
||||
};
|
||||
reader.readAsText(blob, "UTF-8");
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ class ContentList extends React.Component<ContentListProps, ContentListState> {
|
||||
chapters: this.props.htmlBook.chapters,
|
||||
});
|
||||
}
|
||||
handleJump(event: any) {
|
||||
async handleJump(event: any) {
|
||||
event.preventDefault();
|
||||
let href = event.target.getAttribute("href");
|
||||
let chapterIndex = _.findIndex(this.props.htmlBook.flattenChapters, {
|
||||
@@ -29,7 +29,7 @@ class ContentList extends React.Component<ContentListProps, ContentListState> {
|
||||
console.log(chapterIndex, this.props.htmlBook.flattenChapters);
|
||||
let title = this.props.htmlBook.flattenChapters[chapterIndex].title;
|
||||
let index = this.props.htmlBook.flattenChapters[chapterIndex].index;
|
||||
this.props.htmlBook.rendition.goToChapter(index.toString(), href, "");
|
||||
await this.props.htmlBook.rendition.goToChapter(index.toString(), href, "");
|
||||
this.props.handleCurrentChapter(title);
|
||||
this.props.handleCurrentChapterIndex(index);
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ class NavList extends React.Component<NavListProps, NavListState> {
|
||||
) : null}
|
||||
<div
|
||||
className="book-bookmark-link"
|
||||
onClick={() => {
|
||||
this.handleJump(item.cfi);
|
||||
onClick={async () => {
|
||||
await this.handleJump(item.cfi);
|
||||
}}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
|
||||
@@ -21,17 +21,18 @@ class Background extends React.Component<BackgroundProps, BackgroundState> {
|
||||
this.isFirst = true;
|
||||
}
|
||||
|
||||
async UNSAFE_componentWillReceiveProps(nextProps: BackgroundProps) {
|
||||
UNSAFE_componentWillReceiveProps(nextProps: BackgroundProps) {
|
||||
if (nextProps.htmlBook !== this.props.htmlBook && nextProps.htmlBook) {
|
||||
await this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
nextProps.htmlBook.rendition.on("page-changed", async () => {
|
||||
await this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
await this.handleLocation();
|
||||
this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
nextProps.htmlBook.rendition.on("page-changed", () => {
|
||||
this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
this.handleLocation();
|
||||
});
|
||||
}
|
||||
}
|
||||
handleLocation = async () => {
|
||||
let position = await this.props.htmlBook.rendition.getPosition();
|
||||
handleLocation = () => {
|
||||
let position = this.props.htmlBook.rendition.getPosition();
|
||||
console.log(position);
|
||||
RecordLocation.recordHtmlLocation(
|
||||
this.props.currentBook.key,
|
||||
position.text,
|
||||
@@ -43,8 +44,8 @@ class Background extends React.Component<BackgroundProps, BackgroundState> {
|
||||
position.cfi
|
||||
);
|
||||
};
|
||||
async handlePageNum(rendition) {
|
||||
let pageInfo = await rendition.getProgress();
|
||||
handlePageNum(rendition) {
|
||||
let pageInfo = rendition.getProgress();
|
||||
this.setState({
|
||||
prevPage: this.state.isSingle
|
||||
? pageInfo.currentPage
|
||||
|
||||
@@ -38,10 +38,10 @@ class OperationPanel extends React.Component<
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.htmlBook.rendition.on("page-changed", async () => {
|
||||
this.props.htmlBook.rendition.on("page-changed", () => {
|
||||
this.speed = Date.now() - this.timeStamp;
|
||||
this.timeStamp = Date.now();
|
||||
let pageProgress = await this.props.htmlBook.rendition.getProgress();
|
||||
let pageProgress = this.props.htmlBook.rendition.getProgress();
|
||||
this.setState({
|
||||
timeLeft:
|
||||
((pageProgress.totalPage - pageProgress.currentPage) * this.speed) /
|
||||
@@ -91,7 +91,7 @@ class OperationPanel extends React.Component<
|
||||
}
|
||||
StorageUtil.setReaderConfig("isFullscreen", "no");
|
||||
}
|
||||
handleAddBookmark = async () => {
|
||||
handleAddBookmark = () => {
|
||||
let bookKey = this.props.currentBook.key;
|
||||
let bookLocation = RecordLocation.getHtmlLocation(bookKey);
|
||||
let text = bookLocation.text;
|
||||
@@ -100,7 +100,7 @@ class OperationPanel extends React.Component<
|
||||
|
||||
let cfi = JSON.stringify(bookLocation);
|
||||
if (!text) {
|
||||
text = await this.props.htmlBook.rendition.visibleText();
|
||||
text = this.props.htmlBook.rendition.visibleText();
|
||||
}
|
||||
text = text
|
||||
.replace(/\s\s/g, "")
|
||||
|
||||
@@ -22,16 +22,16 @@ class ProgressPanel extends React.Component<
|
||||
};
|
||||
}
|
||||
|
||||
async UNSAFE_componentWillReceiveProps(nextProps: ProgressPanelProps) {
|
||||
UNSAFE_componentWillReceiveProps(nextProps: ProgressPanelProps) {
|
||||
if (nextProps.htmlBook !== this.props.htmlBook && nextProps.htmlBook) {
|
||||
await this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
nextProps.htmlBook.rendition.on("page-changed", async () => {
|
||||
await this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
this.handlePageNum(nextProps.htmlBook.rendition);
|
||||
});
|
||||
}
|
||||
}
|
||||
async handlePageNum(rendition) {
|
||||
let pageInfo = await rendition.getProgress();
|
||||
handlePageNum(rendition) {
|
||||
let pageInfo = rendition.getProgress();
|
||||
this.setState({
|
||||
currentPage: this.state.isSingle
|
||||
? pageInfo.currentPage
|
||||
@@ -39,14 +39,14 @@ class ProgressPanel extends React.Component<
|
||||
totalPage: pageInfo.totalPage,
|
||||
});
|
||||
}
|
||||
onProgressChange = (event: any) => {
|
||||
onProgressChange = async (event: any) => {
|
||||
const percentage = event.target.value / 100;
|
||||
if (this.props.htmlBook.flattenChapters.length > 0) {
|
||||
let chapterIndex =
|
||||
percentage === 1
|
||||
? this.props.htmlBook.flattenChapters.length - 1
|
||||
: Math.floor(this.props.htmlBook.flattenChapters.length * percentage);
|
||||
this.props.htmlBook.rendition.goToChapter(
|
||||
await this.props.htmlBook.rendition.goToChapter(
|
||||
this.props.htmlBook.flattenChapters[chapterIndex].index.toString(),
|
||||
this.props.htmlBook.flattenChapters[chapterIndex].href,
|
||||
""
|
||||
@@ -63,10 +63,10 @@ class ProgressPanel extends React.Component<
|
||||
this.props.htmlBook.rendition.prevChapter();
|
||||
}
|
||||
};
|
||||
handleJumpChapter = (event: any) => {
|
||||
handleJumpChapter = async (event: any) => {
|
||||
let targetChapter = parseInt(event.target.value.trim()) - 1;
|
||||
if (this.props.htmlBook.flattenChapters.length > 0) {
|
||||
this.props.htmlBook.rendition.goToChapter(
|
||||
await this.props.htmlBook.rendition.goToChapter(
|
||||
this.props.htmlBook.flattenChapters[targetChapter].index,
|
||||
this.props.htmlBook.flattenChapters[targetChapter].href,
|
||||
""
|
||||
|
||||
@@ -159,7 +159,7 @@ class Reader extends React.Component<ReaderProps, ReaderState> {
|
||||
className="previous-chapter-single-container"
|
||||
onClick={async () => {
|
||||
this.props.htmlBook.rendition.prev();
|
||||
await this.handleLocation();
|
||||
this.handleLocation();
|
||||
}}
|
||||
>
|
||||
<span className="icon-dropdown previous-chapter-single"></span>
|
||||
|
||||
@@ -38,16 +38,10 @@ class RecordLocation {
|
||||
localStorage.setItem("recordLocation", JSON.stringify(obj));
|
||||
} else {
|
||||
if (
|
||||
(!text ||
|
||||
!chapterTitle ||
|
||||
!chapterDocIndex ||
|
||||
!chapterHref ||
|
||||
!count ||
|
||||
!percentage) &&
|
||||
(!text || !chapterTitle || !chapterDocIndex || !count || !percentage) &&
|
||||
document.location.href.indexOf("/cb") === -1 //漫画的情况,cbr,cbt,cbz
|
||||
)
|
||||
return;
|
||||
|
||||
let json = localStorage.getItem("recordLocation");
|
||||
let obj = JSON.parse(json || "{}");
|
||||
obj[bookKey] = {
|
||||
|
||||
@@ -136,8 +136,8 @@ const gesture = (rendition: any, type: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLocation = async (key: string, rendition: any) => {
|
||||
let position = await rendition.getPosition();
|
||||
const handleLocation = (key: string, rendition: any) => {
|
||||
let position = rendition.getPosition();
|
||||
RecordLocation.recordHtmlLocation(
|
||||
key,
|
||||
position.text,
|
||||
|
||||
Reference in New Issue
Block a user