Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1012
  • Loading branch information
dteviot committed Oct 14, 2023
1 parent 9c62acf commit 1721f13
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
72 changes: 72 additions & 0 deletions plugin/js/parsers/NovelmediumParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use strict";

parserFactory.register("novelmedium.com", () => new NovelmediumParser());

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

async getChapterUrls(dom) {
let url = dom.baseURI;
if (url.includes("#")) {
url = url.substring(0, url.indexOf("#"));
}
let storyId = this.getStoryId(dom, url);
return this.fetchToc(storyId, url);
}

getStoryId(dom, url) {
let script = [...dom.querySelectorAll("script")]
.filter(s => s.innerText.includes("__NUXT__"))[0]
let blobs = script.innerText.split("{id:");
let leaf = url.substring(url.lastIndexOf("/") + 1);
let blob = blobs.filter(b => b.includes(leaf))[0];
return blob.split(",")[0];
}

async fetchToc(storyId, baseUrl) {
let options = {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
credentials: "include",
body: this.createPayload(storyId)
};
let json = (await HttpClient.fetchJson("https://novelmedium.com/api/__api_party/novelmedium-api", options)).json;
return json._data.map(j => this.jsonToChapter(j, baseUrl));
}

createPayload(storyId) {
let payload = {
path: "frontend/allchapters/" + storyId,
headers: { }
};
return JSON.stringify(payload);
}

jsonToChapter(json, baseUrl) {
return ({
sourceUrl: baseUrl + "/" + json.slug,
title: json.title
});
}

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

findChapterTitle(dom) {
return dom.querySelector("div.chapter-container .heading h2");
}

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

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll(".summary")];
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ <h3>Instructions</h3>
<script src="js/parsers/NovelholdParser.js"></script>
<script src="js/parsers/NovelmaoParser.js"></script>
<script src="js/parsers/NovelmaniaParser.js"></script>
<script src="js/parsers/NovelmediumParser.js"></script>
<script src="js/parsers/NovelNaverParser.js"></script>
<script src="js/parsers/NovelOnlineFreeParser.js"></script>
<script src="js/parsers/NovelonomiconParser.js"></script>
Expand Down

0 comments on commit 1721f13

Please sign in to comment.