From 6437bb59a780000d0f7fd9de40180677884d103b Mon Sep 17 00:00:00 2001 From: dteviot Date: Tue, 17 Sep 2024 09:55:18 +1200 Subject: [PATCH] Add site https://wfxs.tw/ See: https://github.com/dteviot/WebToEpub/issues/1487 --- plugin/js/parsers/WfxsParser.js | 62 +++++++++++++++++++++++++++++++++ plugin/popup.html | 1 + 2 files changed, 63 insertions(+) create mode 100644 plugin/js/parsers/WfxsParser.js diff --git a/plugin/js/parsers/WfxsParser.js b/plugin/js/parsers/WfxsParser.js new file mode 100644 index 00000000..88bd3359 --- /dev/null +++ b/plugin/js/parsers/WfxsParser.js @@ -0,0 +1,62 @@ +"use strict"; + +parserFactory.register("wfxs.tw", () => new WfxsParser()); + +class WfxsParser extends Parser{ + constructor() { + super(); + } + + async getChapterUrls(dom) { + let tocUrl = this.makeTocUrl(dom.baseURI); + let tocHtml = (await HttpClient.wrapFetch(tocUrl)).responseXML; + let menu = [...tocHtml.querySelectorAll("#readerlists")].pop(); + return util.hyperlinksToChapterList(menu); + } + + makeTocUrl(url) { + return url.substring(0, url.length - 1) + .replace("xiaoshuo", "booklist") + ".html"; + } + + findContent(dom) { + return Parser.findConstrutedContent(dom); + } + + extractTitleImpl(dom) { + return dom.querySelector(".booktitle h1"); + } + + findCoverImageUrl(dom) { + return util.getFirstImgSrc(dom, "#bookimg"); + } + + async fetchChapter(url) { + let newDoc = Parser.makeEmptyDocForContent(url); + let dom = (await HttpClient.wrapFetch(url)).responseXML; + newDoc.content.appendChild(this.findRawContent(dom)); + let nextPageUrl = this.findNextPageUrl(dom); + while (nextPageUrl != null) { + dom = (await HttpClient.wrapFetch(nextPageUrl)).responseXML; + newDoc.content.appendChild(this.findRawContent(dom)); + nextPageUrl = this.findNextPageUrl(dom); + } + return newDoc.dom; + } + + findRawContent(dom) { + return dom.querySelector(".chapter-content"); + } + + findNextPageUrl(dom) { + let link = [...dom.querySelectorAll(".foot-nav a")] + .map(l => l.href)[2]; + return ((link != null) && link.endsWith(".html")) + ? link + : null; + } + + getInformationEpubItemChildNodes(dom) { + return [...dom.querySelectorAll("#intro_win p")]; + } +} diff --git a/plugin/popup.html b/plugin/popup.html index 865173d3..59abef2f 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -772,6 +772,7 @@

Instructions

+