Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1475
  • Loading branch information
dteviot committed Sep 10, 2024
1 parent 0c06d7e commit 541dcc1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions plugin/js/parsers/NtruyenParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"use strict";

parserFactory.register("ntruyen.vn", () => new NtruyenParser());

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

async getChapterUrls(dom, chapterUrlsUI) {
let chapters = this.extractPartialChapterList(dom);
chapterUrlsUI.showTocProgress(chapters);

let numPages = this.getNumOfTocPages(dom);
let storyId = this.getStoryId(dom);
for(let i = 2; i <= numPages; ++i) {
let formData = this.createFormData(storyId, i);
let tocPage = await (this.fetchToc(formData));
let partialList = this.extractPartialChapterList(tocPage);
chapterUrlsUI.showTocProgress(partialList);
chapters = chapters.concat(partialList);
}
return chapters;
}

extractPartialChapterList(dom) {
let menu = dom.querySelector("ul.chapter-list");
return util.hyperlinksToChapterList(menu);
}

getNumOfTocPages(dom) {
let val = dom.querySelector(".goto button")?.getAttribute("data-total");
return val != null
? parseInt(val)
: 1;
}

getStoryId(dom) {
return dom.baseURI.split("-").pop().split(".")[0];
}

async fetchToc(formData) {
let options = {
method: "POST",
credentials: "include",
body: formData
};
let json = (await HttpClient.fetchJson("https://ntruyen.vn//ajax/load_chapter", options)).json;
return new DOMParser().parseFromString(json.chapters, "text/html");;
}

createFormData(storyId, page) {
let formData = new FormData();
formData.append("story_id", storyId);
formData.append("page", page);
return formData;
}

findContent(dom) {
return dom.querySelector("#chapter-content");
}

extractTitleImpl(dom) {
return dom.querySelector(".story-title h1");
}

extractAuthor(dom) {
let authorLabel = dom.querySelector(".story-title a");
return authorLabel?.textContent ?? super.extractAuthor(dom);
}

findChapterTitle(dom) {
return dom.querySelector(".chapter-infos h1");
}

findCoverImageUrl(dom) {
return util.getFirstImgSrc(dom, ".cover");
}

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll(".description")];
}
}
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/NovelversetranslationsParser.js"></script>
<script src="js/parsers/NovicetranslationsParser.js"></script>
<script src="js/parsers/NrvnqsrParser.js"></script>
<script src="js/parsers/NtruyenParser.js"></script>
<script src="js/parsers/NyantlParser.js"></script>
<script src="js/parsers/OctopiiParser.js"></script>
<script src="js/parsers/OnlinenovelbookParser.js"></script>
Expand Down

0 comments on commit 541dcc1

Please sign in to comment.