Skip to content

Commit

Permalink
Add footnotes for www.chickengege.org
Browse files Browse the repository at this point in the history
See: #1071
  • Loading branch information
dteviot committed Sep 15, 2023
1 parent 70dd1f9 commit d7f807a
Showing 3 changed files with 54 additions and 1 deletion.
25 changes: 25 additions & 0 deletions plugin/js/parsers/ChickengegeParser.js
Original file line number Diff line number Diff line change
@@ -28,4 +28,29 @@ class ChickengegeParser extends Parser{
findChapterTitle(dom) {
return dom.querySelector("h1.entry-title");
}

preprocessRawDom(webPageDom) {
let content = this.findContent(webPageDom);
let footnotes = this.extractFootnotes(webPageDom);
this.moveFootnotes(webPageDom, content, footnotes);
}

extractFootnotes(dom) {
return [...dom.querySelectorAll("script")]
.filter(s => s.textContent.includes("{ toolTips("))
.map(s => this.scriptToSpan(s, dom));
}

scriptToSpan(script, dom) {
let span = dom.createElement("span");
span.textContent = this.extractFootnoteText(script);
return span;
}

extractFootnoteText(script) {
let content = script.textContent.replace("jQuery(\"document\")", "");
let start = content.indexOf("\"") + 1;
let end = content.lastIndexOf("\",'");
return content.substring(start, end);
}
}
4 changes: 3 additions & 1 deletion unitTest/Tests.html
Original file line number Diff line number Diff line change
@@ -33,11 +33,13 @@
<script src="../plugin/js/DefaultParserUI.js"></script>
<script src="../plugin/js/ProgressBar.js"></script>
<script src="../plugin/js/Parser.js"></script>
<script src="../plugin/js/parsers/WordpressBaseParser.js"></script>
<script src="../plugin/js/parsers/ActiveTranslationsParser.js"></script>
<script src="../plugin/js/parsers/ArchiveOfOurOwnParser.js"></script>
<script src="../plugin/js/parsers/BakaTsukiParser.js"></script>
<script src="../plugin/js/parsers/BakaTsukiSeriesPageParser.js"></script>
<script src="../plugin/js/parsers/BlogspotParser.js"></script>
<script src="../plugin/js/parsers/ChickengegeParser.js"></script>
<script src="../plugin/js/parsers/ChineseFantasyNovelsParser.js"></script>
<script src="../plugin/js/parsers/ComrademaoParser.js"></script>
<script src="../plugin/js/parsers/DefaultParser.js"></script>
@@ -67,7 +69,6 @@
<script src="../plugin/js/parsers/TapreadParser.js"></script>
<script src="../plugin/js/parsers/TruyenfullParser.js"></script>
<script src="../plugin/js/parsers/TruyenyyParser.js"></script>
<script src="../plugin/js/parsers/WordpressBaseParser.js"></script>
<script src="../plugin/js/parsers/AsianHobbyistParser.js"></script>
<script src="../plugin/js/parsers/LightNovelsTranslationsParser.js"></script>
<script src="../plugin/js/parsers/NepustationParser.js"></script>
@@ -102,6 +103,7 @@
<script src="UtestActiveTranslationsParser.js"></script>
<script src="UtestBakaTsukiParser.js"></script>
<script src="UtestBlogspotParser.js"></script>
<script src="UtestChickengegeParser.js"></script>
<script src="UtestChineseFantasyNovelsParser.js"></script>
<script src="UtestComrademaoParser.js"></script>
<script src="UtestDefaultParser.js"></script>
26 changes: 26 additions & 0 deletions unitTest/UtestChickengegeParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

module("ChickengegeParser");

test("extractFootnotes", function (assert) {
let dom = new DOMParser().parseFromString(ChickengegeChapterSample, "text/html");
let parser = new ChickengegeParser();
let actual = parser.extractFootnotes(dom);
assert.equal(actual.length, 2);
assert.equal(actual[0].textContent, "Iuppiter = old English form of Jupiter; raws used an ancient term for Jupiter");
assert.equal(actual[1].textContent, "10-15 minutes");
});

let ChickengegeChapterSample =
`<!DOCTYPE html>
<html lang="en">
<head>
<title>The Beginning After The End - Chapter 1 - The Light at the End of the Tunnel - WebNovelOnline</title>
<base href="https://webnovelonline.com/chapter/the_beginning_after_the_end/chapter-1" />
</head>
<body>
<p style="text-align: justify">“Don’t worry.” Chen Xing explained, “<span class="tooltipsall tooltip_post_id_custom_1444bf0d1c43826214fbd5a251167080 classtoolTipsCustomShortCodeOnlyForMultiTooltips">Iuppiter</span><script type="b7f1d86dd5bddd712eb9cb17-text/javascript">jQuery("document").ready(function(){ toolTips('.tooltip_post_id_custom_1444bf0d1c43826214fbd5a251167080',"Iuppiter = old English form of Jupiter; raws used an ancient term for Jupiter",'0'); });</script> is part of my fate. Up until now, no matter what I encounter, I’m able to avert disaster.” He then went out to search for a horse.</p>
<p style="text-align: justify">Chen Xing hung himself for approximately the time taken to drink a cup of <span class="tooltipsall tooltip_post_id_custom_8444618342de8febdd65e67c9055cc15 classtoolTipsCustomShortCodeOnlyForMultiTooltips">tea</span><script type="b7f1d86dd5bddd712eb9cb17-text/javascript">jQuery("document").ready(function(){ toolTips('.tooltip_post_id_custom_8444618342de8febdd65e67c9055cc15',"10-15 minutes",'0'); });</script>, confirmed that no one else was coming again, then quickly untied the knot and came down. He carried Xiang Shu on his shoulder and ran towards the backyard as he gasped for breath.</p>
</body>
</html>
`

0 comments on commit d7f807a

Please sign in to comment.