Skip to content

Commit

Permalink
Tag Novelbin watermark
Browse files Browse the repository at this point in the history
Moves watermarks into a <span> tag, just like the site code
does when viewing in a browser.

See: #1446
  • Loading branch information
dteviot committed Sep 22, 2024
1 parent 2502e17 commit 57acb6e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
36 changes: 36 additions & 0 deletions plugin/js/parsers/NovelfullParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class NovelfullParser extends Parser{
: super.extractAuthor(dom);
}

preprocessRawDom(dom) {
this.tagWatermark(dom);
}

findChapterTitle(dom) {
return dom.querySelector("h2").textContent;
}
Expand All @@ -132,6 +136,38 @@ class NovelfullParser extends Parser{
getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll("div.desc-text, div.info")];
}

tagWatermark(dom) {
const watermark = this.findWatermark(dom);
if (watermark) {
let paragraphs = [...dom.querySelectorAll("p")]
.filter(p => p.textContent.includes(watermark));
for(let p of paragraphs) {
p.textContent = p.textContent.replace(watermark, "");
p.appendChild(this.makeSpanWithWatermark(dom, watermark));
}
}
}

findWatermark(dom) {
const searchToken = "original11Content.replace(\"";
const script = [...dom.querySelectorAll("script")]
.filter(s => s.innerHTML.includes(searchToken))
.map(s => s.innerHTML)[0];
if (!script) {
return null;
}
const line = script.substring(script.indexOf(searchToken) + searchToken.length);
return line.substring(0, line.indexOf("\""));
}

makeSpanWithWatermark(dom, watermark) {
let span = dom.createElement("span");
span.textContent = watermark;
span.id = "span";
span.hidden = true;
return span;
}
}

class Novel35Parser extends NovelfullParser{
Expand Down
2 changes: 2 additions & 0 deletions unitTest/Tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<script src="../plugin/js/parsers/MangadexParser.js"></script>
<script src="../plugin/js/parsers/MangaHereParser.js"></script>
<script src="../plugin/js/parsers/MuggleNetParser.js"></script>
<script src="../plugin/js/parsers/NovelfullParser.js"></script>
<script src="../plugin/js/parsers/NovelSpreadParser.js"></script>
<script src="../plugin/js/parsers/NovelUniverseParser.js"></script>
<script src="../plugin/js/parsers/NovelUpdatesParser.js"></script>
Expand Down Expand Up @@ -124,6 +125,7 @@
<script src="UtestMuggleNetParser.js"></script>
<script src="UtestNepustationParser.js"></script>
<script src="UtestNovelSpreadParser.js"></script>
<script src="UtestNovelfullParser.js"></script>
<script src="UtestNovelUpdatesParser.js"></script>
<script src="UtestQidianParser.js"></script>
<script src="UtestQinxiaoshuoParser.js"></script>
Expand Down
57 changes: 57 additions & 0 deletions unitTest/UtestNovelfullParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

"use strict";

module("NovelfullParser");

QUnit.test("findWatermark", function (assert) {
let dom = new DOMParser().parseFromString(NovelfullSample, "text/html");
let parser = new NovelfullParser();
let watermark = parser.findWatermark(dom);
assert.equal(watermark, "n/ô/vel/b//jn dot c//om");
});

QUnit.test("tagWatermark", function (assert) {
let dom = new DOMParser().parseFromString(NovelfullSample, "text/html");
let parser = new NovelfullParser();
parser.tagWatermark(dom);
let paragraph = dom.querySelector("#watermarked");
let span = paragraph.querySelector("span");
assert.equal(span.innerHTML, "n/ô/vel/b//jn dot c//om");
assert.equal(paragraph.childNodes[0].nodeValue, " Yuan found their wording quite weird, but who was he to judge their world? ");
});

let NovelfullSample =
`<!DOCTYPE html>
<html lang="en">
<head>
<title>Cultivation Online #Chapter 1596 Primal Expanse - Read Cultivation Online Chapter 1596 Primal Expanse Online - All Page - Novel Bin</title>
</head>
<body>
<div id="chr-content">
<div id="pf-10311-1">
<script>window.pubfuturetag = window.pubfuturetag || [];window.pubfuturetag.push({unit: "66b4e3c40939a022784366eb", id: "pf-10311-1"})</script></div>
<div></div>
<h3>Chapter 1596 &nbsp;Primal Expanse</h3> <p> </p><p> After taking a moment to digest the possibility that they had been transported to another world outside the Nine Heavens, Yuan turned to look at the mysterious naked little girl and asked, "Do you mind telling us a little about the Primal Expanse?" </p><div id="pf-10364-1">
<script>window.pubfuturetag = window.pubfuturetag || [];window.pubfuturetag.push({unit: "66b9b2575d6f5a59dab6ff6d", id: "pf-10364-1"})</script></div><p id="watermarked"> Yuan found their wording quite weird, but who was he to judge their world? n/ô/vel/b//jn dot c//om</p><p> "Primal and Predators, right? I will remember that." </p>
<div id="pf-10366-1">
<script>window.pubfuturetag = window.pubfuturetag || [];window.pubfuturetag.push({unit: "66b9b27899ef0d23774745cd", id: "pf-10366-1"})</script></div>
</div>
<script>
setTimeout(function () {
const paragraphss = $("p");
paragraphss.each(function () {
const original11Content = $(this).html();
const updated11Content = original11Content.replace("n/ô/vel/b//jn dot c//om", \`<span id="span">n/ô/vel/b//jn dot c//om</span>\`);
$(this).html(updated11Content);
});
}, 600000);
</script>
</body>
</html>`

0 comments on commit 57acb6e

Please sign in to comment.