forked from dteviot/WebToEpub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See: dteviot#1344
- Loading branch information
Showing
2 changed files
with
37 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,36 @@ | ||
"use strict"; | ||
|
||
parserFactory.register("reddit.com", () => new RedditParser()); | ||
|
||
class RedditParser extends Parser{ | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async getChapterUrls(dom) { | ||
return [...dom.querySelectorAll("div.wiki a")] | ||
.filter(RedditParser.IsChapterLink) | ||
.map(a => util.hyperLinkToChapter(a)); | ||
} | ||
|
||
findContent(dom) { | ||
return RedditParser.getPost(dom)?.querySelector("[slot='text-body']"); | ||
} | ||
|
||
extractTitleImpl(dom) { | ||
return dom.querySelector(".toc a"); | ||
} | ||
|
||
static IsChapterLink(link) { | ||
let pathname = new URL(link.href).pathname; | ||
return pathname.startsWith("/r/HFY/comments/"); | ||
} | ||
|
||
static getPost(dom) { | ||
return dom.querySelector("main shreddit-post"); | ||
} | ||
|
||
findChapterTitle(dom) { | ||
return RedditParser.getPost(dom).querySelector("h1"); | ||
} | ||
} |
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