Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dteviot committed Jun 16, 2024
1 parent 1fb194c commit 1c86f38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions plugin/js/parsers/RedditParser.js
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");
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ <h3>Instructions</h3>
<script src="js/parsers/ReadwnParser.js"></script>
<script src="js/parsers/ReaperscansParser.js"></script>
<script src="js/parsers/RebirthOnline.js"></script>
<script src="js/parsers/RedditParser.js"></script>
<script src="js/parsers/RoyalRoadParser.js"></script>
<script src="js/parsers/RtdMoeParser.js"></script>
<script src="js/parsers/RtenzoParser.js"></script>
Expand Down

0 comments on commit 1c86f38

Please sign in to comment.