Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1111
  • Loading branch information
dteviot committed Dec 9, 2023
1 parent df54d79 commit 6217d57
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions plugin/js/parsers/RaeitranslationsParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";

parserFactory.register("raeitranslations.com", () => new RaeitranslationsParser());

class RaeitranslationsParser extends Parser{
constructor() {
super();
}

async getChapterUrls(dom) {
return [...dom.querySelectorAll("div.chapter-list a")]
.map(this.linkToChapter);
}

linkToChapter(link) {
return {
sourceUrl: link.href,
title: link.querySelector(".chapter-title").innerText.trim(),
};
}

findContent(dom) {
return Parser.findConstrutedContent(dom);
}

extractTitleImpl(dom) {
return dom.querySelector("h2.title");
}

findCoverImageUrl(dom) {
let div = dom.querySelector("div.img.wrapper [style*=background-image]");
return "https://raeitranslations.com" + util.extractUrlFromBackgroundImage(div);
}

async fetchChapter(url) {
let restUrl = this.makeRestUrl(url);
let json = (await HttpClient.fetchJson(restUrl)).json;
let content = this.buildHtml(json.currentChapter);
let newDoc = Parser.makeEmptyDocForContent(url);
newDoc.content.appendChild(content);
return newDoc.dom;
}

makeRestUrl(chapterUrl) {
let path = new URL(chapterUrl).pathname.split("/");
let restUrl = new URL("https://api.raeitranslations.com/api/chapters/");
restUrl.searchParams.set("id", path[1]);
restUrl.searchParams.set("num", path[2]);
return restUrl;
}

buildHtml(json) {
let paragraphs = json.body.replace(/\n/g, "</p><p>");
let html = `<div><h1>${json.chapTitle}</h1><p>${paragraphs}</p></div>`;
let doc = new DOMParser().parseFromString(html, "text/html")
return doc.querySelector("div");
}

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll("div.white-space")];
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ <h3>Instructions</h3>
<script src="js/parsers/QuestionableQuestingParser.js"></script>
<script src="js/parsers/QuanbenParser.js"></script>
<script src="js/parsers/QuotevParser.js"></script>
<script src="js/parsers/RaeitranslationsParser.js"></script>
<script src="js/parsers/RanobesParser.js"></script>
<script src="js/parsers/RainOfSnowParser.js"></script>
<script src="js/parsers/ReadComicOnlineParser.js"></script>
Expand Down

0 comments on commit 6217d57

Please sign in to comment.