diff --git a/package.json b/package.json index e7f4661c..c27ae57b 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,8 @@ { "name": "senia-psm"}, { "name": "thanhlouis"}, { "name": "ltmerletti"}, - { "name": "fnx4"} + { "name": "fnx4"}, + { "name": "Arcade Wise", "email": "l3gacy.b3ta@gmail.com"} ], "license": "GPL-3.0-only", "bugs": { diff --git a/plugin/js/parsers/AlthistParser.js b/plugin/js/parsers/AlthistParser.js new file mode 100644 index 00000000..581f9301 --- /dev/null +++ b/plugin/js/parsers/AlthistParser.js @@ -0,0 +1,90 @@ +"use strict"; + +parserFactory.register("althistory.com", () => new AlthistoryParser()); + +class AlthistoryParser extends Parser { + constructor() { + super(); + this.cache = new FetchCache(); + this.minimumThrottle = 50; //182 at 20 + this.expectedChapterUrl = null; + } + + async getChapterUrls(dom) { + let chapters = [...dom.querySelectorAll(".threadmark_depth0 > ul > li > a")]; + // .filter(this.isLinkToChapter); + return chapters.map(a => util.hyperLinkToChapter(a)); + } + + isLinkToChapter(link) { + return !link.querySelector("date") + && !(new URL(link.href).pathname.startsWith("/awards/award")); + } + + findContent(dom) { + return Parser.findConstrutedContent(dom); + } + + extractTitleImpl(dom) { + return dom.querySelector(".threadmarkLabel"); + } + + extractAuthor(dom) { + let authorLabel = dom.querySelector("a.username"); + return (authorLabel === null) ? super.extractAuthor(dom) : authorLabel.textContent; + } + + async fetchChapter(url) { + let article = await this.fetchArticle(url); + if (!article && this.expectedChapterUrl && (this.expectedChapterUrl != url)) { + article = await this.fetchArticle(this.expectedChapterUrl); + } + if (article == null) { + throw new Error(`Can not find chapter ${url}`); + } + this.expectedChapterUrl = this.findExpectedNextChapter(article); + + let newDoc = Parser.makeEmptyDocForContent(url); + this.addTitleToChapter(newDoc, article); + let content = article.querySelector("article.message-body"); + util.resolveLazyLoadedImages(content, "img.lazyload"); + newDoc.content.appendChild(content); + return newDoc.dom; + } + + async fetchArticle(url) { + let fetchedDom = await this.cache.fetch(url); + let newUrl = new URL(url); + let id = newUrl.hash.substring(1); + let parent = fetchedDom.querySelector(`article.message[data-content='${id}']`); + if (parent === null) + { + parent = fetchedDom.querySelector("#" + id)?.parentElement; + } + return parent; + } + + findCoverImageUrl(dom) { + return util.getFirstImgSrc(dom, ".threadmarkListingHeader-icon"); + } + + findExpectedNextChapter(article) { + return article.querySelector("li.threadmark-nav") + ?.querySelector("a:nth-of-type(3)") + ?.href; + } + + addTitleToChapter(newDoc, parent) { + let titleElement = parent.querySelector("span.threadmarkLabel"); + if (titleElement !== null) + { + let title = newDoc.dom.createElement("h1"); + title.textContent = titleElement.textContent.trim(); + newDoc.content.appendChild(title); + } + } + + getInformationEpubItemChildNodes(dom) { + return [...dom.querySelectorAll("article.threadmarkListingHeader-extraInfoChild")]; + } +} diff --git a/plugin/popup.html b/plugin/popup.html index 84ecea76..dc064586 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -629,6 +629,7 @@

Instructions

+ diff --git a/readme.md b/readme.md index 93937fa0..8726cbcb 100644 --- a/readme.md +++ b/readme.md @@ -822,6 +822,7 @@ Don't forget to give the project a star! Thanks again!
  • ltmerletti
  • thanhlouis
  • fnx4
  • +
  • Arcade Wise (parser for althistory.com)