-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gamebeaker
committed
Oct 3, 2024
1 parent
a31b6cc
commit 61d8815
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters