-
Notifications
You must be signed in to change notification settings - Fork 148
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://www.botitranslation.com/
See: #1408
- Loading branch information
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("botitranslation.com", () => new BotitranslationParser()); | ||
|
||
class BotitranslationParser extends Parser{ | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async getChapterUrls(dom) { | ||
let menu = dom.querySelector("#tocItems"); | ||
return util.hyperlinksToChapterList(menu); | ||
} | ||
|
||
findContent(dom) { | ||
return Parser.findConstrutedContent(dom); | ||
} | ||
|
||
extractTitleImpl(dom) { | ||
return dom.querySelector(".book-name"); | ||
} | ||
|
||
extractAuthor(dom) { | ||
let authorLabel = dom.querySelector(".author-name"); | ||
return authorLabel?.textContent ?? super.extractAuthor(dom); | ||
} | ||
|
||
removeUnwantedElementsFromContentElement(element) { | ||
util.removeChildElementsMatchingCss(element, "p > br"); | ||
super.removeUnwantedElementsFromContentElement(element); | ||
} | ||
|
||
findCoverImageUrl(dom) { | ||
return util.getFirstImgSrc(dom, ".cover-container"); | ||
} | ||
|
||
async fetchChapter(url) { | ||
let restUrl = this.toRestUrl(url); | ||
let json = (await HttpClient.fetchJson(restUrl)).json; | ||
return this.buildChapter(json, url); | ||
} | ||
|
||
toRestUrl(url) { | ||
let leaves = url.split("/"); | ||
let id = leaves[leaves.length - 1].split("-")[0]; | ||
return "https://api.mystorywave.com/story-wave-backend/api/v1/content/chapters/" + id; | ||
} | ||
|
||
buildChapter(json, url) { | ||
let newDoc = Parser.makeEmptyDocForContent(url); | ||
let title = newDoc.dom.createElement("h1"); | ||
title.textContent = json.data.title; | ||
newDoc.content.appendChild(title); | ||
let content = new DOMParser().parseFromString(json.data.content, "text/html"); | ||
for(let n of [...content.body.childNodes]) { | ||
newDoc.content.appendChild(n); | ||
} | ||
return newDoc.dom; | ||
} | ||
|
||
getInformationEpubItemChildNodes(dom) { | ||
return [...dom.querySelectorAll("#about-panel.synopsis")]; | ||
} | ||
} |
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