Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1580
  • Loading branch information
dteviot committed Dec 2, 2024
1 parent bf91eec commit d329baa
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/OldranobelibParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

parserFactory.register("old.ranobelib.me", () => new OldranobelibParser());

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

async getChapterUrls(dom) {
let base = this.makeChapterBaseUrl(dom);
let json = this.getJsonWithChapters(dom);
return json.map(j => this.jsonToChapters(j, base));
}

getJsonWithChapters(dom) {
let startString = "window.__CONTENT__ = ";
let scriptElement = [...dom.querySelectorAll("script")]
.filter(s => s.textContent.includes(startString))[0];
return util.locateAndExtractJson(scriptElement.textContent, startString)
}

makeChapterBaseUrl(dom) {
let base = new URL(dom.baseURI);
let tip = base.pathname.split("/").pop();
return `https://old.ranobelib.me/old/${tip}/read/`
}

jsonToChapters(json, base) {
let name = json.name;
if (!util.isNullOrEmpty(name)) {
name = " - " + name;
}
return ({
sourceUrl: `${base}v${json.volume}/c${json.number}`,
title: `Том ${json.volume} Глава ${json.number}${name}`
});
}

findContent(dom) {
return dom.querySelector(".reader-container");
}

extractTitleImpl(dom) {
return dom.querySelector(".media-name__main");
}

extractAuthor(dom) {
let authorLabel = dom.querySelector(".media-sidebar .media-info-list__item span");
return authorLabel?.textContent ?? super.extractAuthor(dom);
}

extractLanguage(dom) {
return dom.querySelector("html").getAttribute("lang");
}

findChapterTitle(dom) {
return dom.querySelector("[data-media-down].reader-header-action__title");
}

findCoverImageUrl(dom) {
return util.getFirstImgSrc(dom, ".media-cover");
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ <h3>Instructions</h3>
<script src="js/parsers/NyahFanfictionParser.js"></script>
<script src="js/parsers/NyantlParser.js"></script>
<script src="js/parsers/OctopiiParser.js"></script>
<script src="js/parsers/OldranobelibParser.js"></script>
<script src="js/parsers/OnlinenovelbookParser.js"></script>
<script src="js/parsers/OntimestoryParser.js"></script>
<script src="js/parsers/OssantlParser.js"></script>
Expand Down

0 comments on commit d329baa

Please sign in to comment.