Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
90 changes: 90 additions & 0 deletions plugin/js/parsers/AlthistParser.js
Original file line number Diff line number Diff line change
@@ -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")];
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ <h3>Instructions</h3>
<script src="js/parsers/AerialrainParser.js"></script>
<script src="js/parsers/AkknovelParser.js"></script>
<script src="js/parsers/AlphapolisParser.js"></script>
<script src="js/parsers/AlthistParser.js"></script>
<script src="js/parsers/AliceswParser.js"></script>
<script src="js/parsers/AmoryaoiParser.js"></script>
<script src="js/parsers/AnythingNovelParser.js"></script>
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ Don't forget to give the project a star! Thanks again!
<li>ltmerletti</li>
<li>thanhlouis</li>
<li>fnx4</li>
<li>Arcade Wise (parser for althistory.com)</li>
</ul>
</details>

Expand Down