Skip to content

Commit 56ca08b

Browse files
committed
See: #2698 Note, currently still something of a work in progress.
1 parent 92e460b commit 56ca08b

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"use strict";
2+
3+
parserFactory.register("novelarrow.com", () => new NovelarrowParser());
4+
5+
class NovelarrowParser extends Parser { // eslint-disable-line no-unused-vars
6+
constructor() {
7+
super();
8+
}
9+
10+
async getChapterUrls(dom) {
11+
return [...dom.querySelectorAll(".jsx-6d23f35167deb67d.space-y-6 a")]
12+
.map(a => ({
13+
sourceUrl: a.href,
14+
title: a.querySelector("span.hidden")?.textContent,
15+
}))
16+
.reverse();
17+
}
18+
19+
findContent(dom) {
20+
return Parser.findConstrutedContent(dom);
21+
}
22+
23+
extractTitleImpl(dom) {
24+
return dom.querySelector("h1");
25+
}
26+
27+
extractAuthor(dom) {
28+
let author = dom.querySelector("a[href*='/author/']");
29+
return (author === null) ? super.extractAuthor(dom) : author.innerText; }
30+
31+
// Optional, supply if individual chapter titles are not inside the content element
32+
/*
33+
findChapterTitle(dom) {
34+
// typical implementation is find node with the Title
35+
// Return Title element, OR the title as a string
36+
return dom.querySelector("h3.dashhead-title");
37+
}
38+
*/
39+
40+
findCoverImageUrl(dom) {
41+
return util.getFirstImgSrc(dom, ".novel-cover-frame");
42+
}
43+
44+
preprocessRawDom(webPageDom) {
45+
let content = this.locateContent(webPageDom);
46+
let doc = util.sanitize(`<div class='${Parser.WEB_TO_EPUB_CLASS_NAME}'>"${content}</div>`);
47+
let node = doc.querySelector("."+Parser.WEB_TO_EPUB_CLASS_NAME);
48+
webPageDom.body.appendChild(node);
49+
}
50+
51+
locateContent(webPageDom) {
52+
let encoded = [...webPageDom.querySelectorAll("script")]
53+
.filter(s => this.isContent(s))
54+
.map(s => this.extractContentString(s.textContent))[0];
55+
return encoded
56+
? this.cleanUnicode(encoded)
57+
: "";
58+
}
59+
60+
cleanUnicode(s) {
61+
return s.replace(/\\u003c/g, "<")
62+
.replace(/\\u003e/g, ">")
63+
.replace(/\\"/g, "\"")
64+
.replace(/\\n/g, "");
65+
}
66+
67+
extractContentString(raw) {
68+
let start = raw.indexOf("\"");
69+
let end = raw.lastIndexOf("\"");
70+
return raw.substring(start + 1, end);
71+
}
72+
73+
isContent(script) {
74+
let text = script.textContent;
75+
if (text.includes("self.__next_f.push([1,")) {
76+
let s = this.extractContentString(text);
77+
return s.startsWith("\\u003c");
78+
}
79+
return false;
80+
}
81+
82+
getInformationEpubItemChildNodes(dom) {
83+
return [...dom.querySelectorAll(".site-reading-copy")];
84+
}
85+
}

plugin/popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ <h3>Instructions</h3>
810810
<script src="js/parsers/NoblemtlParser.js"></script>
811811
<script src="js/parsers/Novel543Parser.js"></script>
812812
<script src="js/parsers/NovelAllParser.js"></script>
813+
<script src="js/parsers/NovelarrowParser.js"></script>
813814
<script src="js/parsers/NovelcoolParser.js"></script>
814815
<script src="js/parsers/NovelCrushParser.js"></script>
815816
<script src="js/parsers/NoveldexParser.js"></script>

0 commit comments

Comments
 (0)