-
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.
Add site https://raeitranslations.com/
See: #1111
- Loading branch information
Showing
2 changed files
with
63 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,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")]; | ||
} | ||
} |
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