Skip to content

Commit

Permalink
Book Reader Intersection Handler not firing (#369)
Browse files Browse the repository at this point in the history
* Fixed: Fixed an issue where intersection observer wouldn't be triggered when book page had no images (Book reader bookmark not firing while scrolling #360)
  • Loading branch information
majora2007 authored Jul 6, 2021
1 parent 8095c0e commit 5a0642b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
12 changes: 8 additions & 4 deletions API/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,28 @@ public static class Parser
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Hinowa ga CRUSH! 018 (2019) (Digital) (LuCaZ).cbz, Hinowa ga CRUSH! 018.5 (2019) (Digital) (LuCaZ).cbz
new Regex(
@"^(?!Vol)(?<Series>.*) (?<!vol\. )(?<Chapter>\d+(?:.\d+|-\d+)?)(?: \(\d{4}\))?(\b|_|-)",
@"^(?!Vol)(?<Series>.*)\s(?<!vol\. )(?<Chapter>\d+(?:.\d+|-\d+)?)(?:\s\(\d{4}\))?(\b|_|-)",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Tower Of God S01 014 (CBT) (digital).cbz
new Regex(
@"(?<Series>.*) S(?<Volume>\d+) (?<Chapter>\d+(?:.\d+|-\d+)?)",
@"(?<Series>.*)\sS(?<Volume>\d+)\s(?<Chapter>\d+(?:.\d+|-\d+)?)",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Beelzebub_01_[Noodles].zip, Beelzebub_153b_RHS.zip
new Regex(
@"^((?!v|vo|vol|Volume).)*( |_)(?<Chapter>\.?\d+(?:.\d+|-\d+)?)(?<ChapterPart>b)?( |_|\[|\()",
@"^((?!v|vo|vol|Volume).)*(\s|_)(?<Chapter>\.?\d+(?:.\d+|-\d+)?)(?<ChapterPart>b)?(\s|_|\[|\()",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Yumekui-Merry_DKThias_Chapter21.zip
new Regex(
@"Chapter(?<Chapter>\d+(-\d+)?)", //(?:.\d+|-\d+)?
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// [Hidoi]_Amaenaideyo_MS_vol01_chp02.rar
new Regex(
@"(?<Series>.*)( |_)(vol\d+)?( |_)Chp\.? ?(?<Chapter>\d+)",
@"(?<Series>.*)(\s|_)(vol\d+)?(\s|_)Chp\.? ?(?<Chapter>\d+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Vol 1 Chapter 2
new Regex(
@"(?<Volume>((vol|volume|v))?(\s|_)?\.?\d+)(\s|_)(Chp|Chapter)\.?(\s|_)?(?<Chapter>\d+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled),

};
private static readonly Regex[] MangaEditionRegex = {
Expand Down
51 changes: 30 additions & 21 deletions UI/Web/src/app/book-reader/book-reader/book-reader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,35 +485,44 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
this.updateReaderStyles();
this.topOffset = this.stickyTopElemRef.nativeElement?.offsetHeight;

Promise.all(Array.from(this.readingSectionElemRef.nativeElement.querySelectorAll('img'))
const imgs = this.readingSectionElemRef.nativeElement.querySelectorAll('img');
if (imgs === null || imgs.length === 0) {
this.setupPage(part, scrollTop);
return;
}
Promise.all(Array.from(imgs)
.filter(img => !img.complete)
.map(img => new Promise(resolve => { img.onload = img.onerror = resolve; })))
.then(() => {
this.isLoading = false;
this.scrollbarNeeded = this.readingSectionElemRef.nativeElement.scrollHeight > this.readingSectionElemRef.nativeElement.clientHeight;

// Find all the part ids and their top offset
this.setupPageAnchors();


if (part !== undefined && part !== '') {
this.scrollTo(part);
} else if (scrollTop !== undefined && scrollTop !== 0) {
window.scroll({
top: scrollTop,
behavior: 'smooth'
});
} else {
window.scroll({
top: 0,
behavior: 'smooth'
});
}
this.setupPage(part, scrollTop);
});
}, 10);
});
}

setupPage(part?: string | undefined, scrollTop?: number | undefined) {
this.isLoading = false;
this.scrollbarNeeded = this.readingSectionElemRef.nativeElement.scrollHeight > this.readingSectionElemRef.nativeElement.clientHeight;

// Find all the part ids and their top offset
this.setupPageAnchors();


if (part !== undefined && part !== '') {
this.scrollTo(part);
} else if (scrollTop !== undefined && scrollTop !== 0) {
window.scroll({
top: scrollTop,
behavior: 'smooth'
});
} else {
window.scroll({
top: 0,
behavior: 'smooth'
});
}
}

setPageNum(pageNum: number) {
if (pageNum < 0) {
this.pageNum = 0;
Expand Down

0 comments on commit 5a0642b

Please sign in to comment.