diff --git a/plugin/js/parsers/PatreonParser.js b/plugin/js/parsers/PatreonParser.js index 93981b2c..3292e162 100644 --- a/plugin/js/parsers/PatreonParser.js +++ b/plugin/js/parsers/PatreonParser.js @@ -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); @@ -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; + } }