Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 88xiaoshuoParser #1518

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading