-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1518 from gamebeaker/Add-88xiaoshuo.js
Add 88xiaoshuoParser
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters