diff --git a/plugin/js/parsers/88xiaoshuoParser.js b/plugin/js/parsers/88xiaoshuoParser.js new file mode 100644 index 00000000..b316f799 --- /dev/null +++ b/plugin/js/parsers/88xiaoshuoParser.js @@ -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; + } +} \ No newline at end of file diff --git a/plugin/popup.html b/plugin/popup.html index 56e122f1..7d7961dd 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -534,6 +534,7 @@