Skip to content

Commit

Permalink
Add FanFicParser
Browse files Browse the repository at this point in the history
  • Loading branch information
gamebeaker committed Oct 3, 2024
1 parent a31b6cc commit 61d8815
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions plugin/js/parsers/FanFicParadiseParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

parserFactory.register("fanficparadise.com", () => new FanFicParadiseParser());

class FanFicParadiseParser extends Parser{
constructor() {
super();
this.cache = new FetchCache();
this.minimumThrottle = 50; //182 at 20
}

clampSimultanousFetchSize() {
return 1;
}

async getChapterUrls(dom) {
let chapters = [...dom.querySelectorAll("li.threadmarkListItem 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("h1.p-title-value");
};

extractAuthor(dom) {
let authorLabel = dom.querySelector("a.username");
return (authorLabel === null) ? super.extractAuthor(dom) : authorLabel.textContent;
};

async fetchChapter(url) {
let fetchedDom = await this.cache.fetch(url);
let newDoc = Parser.makeEmptyDocForContent(url);
let newUrl = new URL(url);
let id = newUrl.hash.substring(1) || newUrl.href.substring(newUrl.href.lastIndexOf("/") + 1);
let parent;
if (id == "") {
parent = fetchedDom.querySelector("li.hasThreadmark");
} else {
parent = fetchedDom.querySelector(`li.hasThreadmark[id='${id}']`);
}
this.addTitleToChapter(newDoc, parent);
let content = parent.querySelector(".messageContent article");
util.resolveLazyLoadedImages(content, "img.lazyload");
newDoc.content.appendChild(content);
return newDoc.dom;
}

addTitleToChapter(newDoc, parent) {
let titleElement = parent.querySelector("span.label");
let title = newDoc.dom.createElement("h1");
title.textContent = titleElement.textContent.trim();
newDoc.content.appendChild(title);
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ <h3>Instructions</h3>
<script src="js/parsers/EngnovelParser.js"></script>
<script src="js/parsers/ErofusParser.js"></script>
<script src="js/parsers/ExiledrebelsscanlationsParser.js"></script>
<script src="js/parsers/FanFicParadiseParser.js"></script>
<script src="js/parsers/FanFictionParser.js"></script>
<script src="js/parsers/FastNovelParser.js"></script>
<script src="js/parsers/Ffxs8Parser.js"></script>
Expand Down

0 comments on commit 61d8815

Please sign in to comment.