Skip to content

Commit

Permalink
Merge pull request #1450 from Tyderion/fix-patreon-collections
Browse files Browse the repository at this point in the history
Fix Patreon Collections
  • Loading branch information
dteviot authored Aug 30, 2024
2 parents 461ecca + 1b0a481 commit f691463
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions plugin/js/parsers/PatreonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ class PatreonParser extends Parser{
}

async getChapterUrls(dom) {
if (this.isCollectionList()) {
return this.getCollectionLinks(dom);
}
let cards = [...dom.querySelectorAll("div[data-tag='post-card']")]
return cards
.filter(c => this.hasAccessableContent(c))
.map(s => this.cardToChapter(s)).reverse();
}

getCollectionLinks(dom) {
return [...dom.querySelectorAll("a[href*='posts/']")]
.filter((a) => a.querySelector("h3") != null)
.map(util.hyperLinkToChapter)
.reverse();
}

cardToChapter(card) {
let title = card.querySelector("span[data-tag='post-title']").textContent;
let link = this.getUrlOfContent(card);
Expand Down Expand Up @@ -67,11 +77,39 @@ class PatreonParser extends Parser{
}

extractAuthor(dom) {
if (this.isCollectionList()) {
return this.extractCollectionAuthor(dom);
}
let authorLabel = dom.querySelector("h1");
return (authorLabel === null) ? super.extractAuthor(dom) : authorLabel.textContent;
}

extractCollectionAuthor(dom) {
let title = dom.querySelector("h1");
let parent = title.parentNode;
while (parent.querySelector("a") == null) {
parent = parent.parentNode;
}
return parent.querySelector("a")?.textContent ?? "Not Found";
}

findCoverImageUrl(dom) {
if (this.isCollectionList()) {
return this.extractCollectionCover(dom);
}
return util.getFirstImgSrc(dom, "picture");
}


extractCollectionCover(dom) {
let divsWithPicutres = dom.querySelectorAll("div[src]")
if (divsWithPicutres.length == 0) {
return null;
}
return divsWithPicutres[divsWithPicutres.length - 1].getAttribute("src");
}

isCollectionList() {
return this.state.chapterListUrl?.indexOf("collection") != -1;
}
}

0 comments on commit f691463

Please sign in to comment.