Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1408
  • Loading branch information
dteviot committed Aug 9, 2024
1 parent 76a15be commit d883428
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions plugin/js/parsers/BotitranslationParser.js
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")];
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ <h3>Instructions</h3>
<script src="js/parsers/BlogspotParser.js"></script>
<script src="js/parsers/BookswithqianyaParser.js"></script>
<script src="js/parsers/Booktoki152Parser.js"></script>
<script src="js/parsers/BotitranslationParser.js"></script>
<script src="js/parsers/BoxnovelOrgParser.js"></script>
<script src="js/parsers/BoyloveParser.js"></script>
<script src="js/parsers/Bqg225Parser.js"></script>
Expand Down

0 comments on commit d883428

Please sign in to comment.