Skip to content

Commit

Permalink
Merge pull request #1518 from gamebeaker/Add-88xiaoshuo.js
Browse files Browse the repository at this point in the history
Add 88xiaoshuoParser
  • Loading branch information
gamebeaker authored Sep 27, 2024
2 parents f95bf35 + 93eaae0 commit 9d550d1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions plugin/js/parsers/88xiaoshuoParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use strict";

parserFactory.register("88xiaoshuo.net", () => new _88xiaoshuoParser());
parserFactory.register("m.88xiaoshuo.net", () => new _88xiaoshuoParser());

class _88xiaoshuoParser extends Parser{
constructor() {
super();
this.infoPageDom = null;
}

async getChapterUrls(dom, chapterUrlsUI) {
return this.getChapterUrlsFromMultipleTocPages(dom,
this.extractPartialChapterList,
this.getUrlsOfTocPages,
chapterUrlsUI
);
}

getUrlsOfTocPages(dom) {
let lastPagespan = [...dom.querySelectorAll(".caption > span > a")];
let lastPage = null;
for (let node of lastPagespan) {
if (node.innerText == "尾页") {
lastPage = node;
}
}
let urls = [];
if (lastPage) {
const lastPageNumber = parseInt(lastPage.href.split("/")[4].split("_")[1]);
const baseUrl = lastPage.baseURI.replace(/\/$/, "");
for (let i = 2; i <= lastPageNumber; i++) {
urls.push(`${baseUrl}_${i}`);
}
}
return urls;
}

extractPartialChapterList(dom) {
let chapterList = dom.querySelector(".read");
return [...chapterList.querySelectorAll("a")].map(a => util.hyperLinkToChapter(a));
}

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

extractTitleImpl(dom) {
return dom.querySelector(".name");
}

extractAuthor(dom) {
let element = dom.querySelector(".author > a");
return (element === null) ? null : element.textContent;
}

findChapterTitle(dom) {
let element = dom.querySelector(".headline");
return (element === null) ? null : element.textContent;
}

findCoverImageUrl(dom) {
return dom.querySelector(".detail > img")?.src ?? null;
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ <h3>Instructions</h3>
<script src="js/parsers/230BookParser.js"></script>
<script src="js/parsers/4kswParser.js"></script>
<script src="js/parsers/69shuParser.js"></script>
<script src="js/parsers/88xiaoshuoParser.js"></script>
<script src="js/parsers/888novelParser.js"></script>
<script src="js/parsers/ActiveTranslationsParser.js"></script>
<script src="js/parsers/AdultfanfictionParser.js"></script>
Expand Down

0 comments on commit 9d550d1

Please sign in to comment.