From a13c9274ebedfea47508780bd9d211f1458bc820 Mon Sep 17 00:00:00 2001 From: ldm2060 Date: Thu, 19 Dec 2024 14:23:54 +0800 Subject: [PATCH] fix #711 --- README.md | 2 +- src/router/download.ts | 4 +- src/rules/onePage/original/esjzone.ts | 37 ------- src/rules/special/original/esjzone.ts | 149 ++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 40 deletions(-) delete mode 100644 src/rules/onePage/original/esjzone.ts create mode 100644 src/rules/special/original/esjzone.ts diff --git a/README.md b/README.md index fdc1f23b..31a30aae 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ EPUB 文件请使用相应阅读器阅读。 | [暁](https://www.akatsuki-novels.com/) | ✅ | ❎ | | | [ファンタジー小説](https://www.alphapolis.co.jp/) | ✅ | ❌ | | | [Novel Up Plus](https://novelup.plus/) | ✅ | ❎ | | -| [ESJ](https://www.esjzone.cc/) | ✅ | ❎ | 当前下载EPUB文件可能会遇到问题。解决办法:按F12 弹出开发工具-> 转到网络页(Network)->按ctrl+R重新加载->找到core.js(链接为https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js )->右键选择点击“屏蔽请求网址”->重新刷新网页即可正常下载。 | +| [ESJ](https://www.esjzone.cc/) | ✅ | ❎ | 当前下载EPUB文件可能会遇到问题。
解决办法:
按F12 弹出开发工具-> 转到网络页(Network)->按ctrl+R重新加载->找到core.js(链接为https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js )->右键选择点击“屏蔽请求网址”->重新刷新网页即可正常下载。 |
点击查看全部支持网站 diff --git a/src/router/download.ts b/src/router/download.ts index 59a5f50c..59fe3161 100644 --- a/src/router/download.ts +++ b/src/router/download.ts @@ -656,8 +656,8 @@ export async function getRule(): Promise { } case "www.esjzone.cc": case "www.esjzone.me": { - const { esjzone } = await import("../rules/onePage/original/esjzone"); - ruleClass = esjzone(); + const { esjzone } = await import("../rules/special/original/esjzone"); + ruleClass = esjzone; break; } /** 笔趣阁END **/ diff --git a/src/rules/onePage/original/esjzone.ts b/src/rules/onePage/original/esjzone.ts deleted file mode 100644 index 67e246fb..00000000 --- a/src/rules/onePage/original/esjzone.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { rm } from "../../../lib/dom"; -import { mkRuleClass } from "../template"; - -export const esjzone = () => - mkRuleClass({ - bookUrl: document.location.href, - bookname: ( - document.querySelector(".book-detail h2") as HTMLElement - ).innerText.trim(), - author: ( - Array.from(document.querySelectorAll('ul.book-detail li')).find( - li => li.textContent && li.textContent.includes('作者:') - )?.querySelector('a') as HTMLAnchorElement | null - )?.innerText.trim() || "Unknown Author", - introDom: document.querySelector(".description") as HTMLElement, - introDomPatch: (dom) => dom, - additionalMetadatePatch: (additionalMetadate) => { - additionalMetadate.tags = Array.from( - document.querySelectorAll( - 'section.widget-tags.m-t-20 a.tag' - ) - ).map((a) => (a as HTMLAnchorElement).innerText); - return additionalMetadate; - }, - coverUrl: document.querySelector("div.product-gallery")?.querySelector("img")?.getAttribute("src") ?? null, - aList: document.querySelectorAll('#chapterList a'), - getAName: (aElem) => - (aElem as HTMLElement)?.innerText.trim(), - getContent: (dom) => dom.querySelector('.forum-content'), - contentPatch: (dom) => { - rm('h3', true, dom); - rm('footer', true, dom); - return dom; - }, - language: "zh", - needLogin: true, - }); diff --git a/src/rules/special/original/esjzone.ts b/src/rules/special/original/esjzone.ts new file mode 100644 index 00000000..fdef0152 --- /dev/null +++ b/src/rules/special/original/esjzone.ts @@ -0,0 +1,149 @@ +import { rm } from "../../../lib/dom"; +import { BaseRuleClass } from "../../../rules"; +import { Book, BookAdditionalMetadate } from "../../../main/Book"; +import { getHtmlDOM } from "../../../lib/http"; +import { cleanDOM } from "../../../lib/cleanDOM"; +import { Chapter } from "../../../main/Chapter"; +import { introDomHandle } from "../../../lib/rule"; +import { getAttachment } from "../../../lib/attachments"; +import { log } from "../../../log"; + +export class esjzone extends BaseRuleClass { + public constructor() { + super(); + this.attachmentMode = "TM"; + } + public async bookParse() { + const bookUrl = document.location.href; + const bookname = ( + document.querySelector(".book-detail h2") as HTMLElement + ).innerText.trim(); + const author = ( + Array.from(document.querySelectorAll('ul.book-detail li')).find( + li => li.textContent && li.textContent.includes('作者:') + )?.querySelector('a') as HTMLAnchorElement | null + )?.innerText.trim() || "Unknown Author"; + const introDom = document.querySelector(".description") as HTMLElement; + const [introduction, introductionHTML] = await introDomHandle(introDom); + const additionalMetadate: BookAdditionalMetadate = {}; + additionalMetadate.tags = Array.from( + document.querySelectorAll( + 'section.widget-tags.m-t-20 a.tag' + ) + ).map((a) => (a as HTMLAnchorElement).innerText); + const isVIP = false; + const isPaid = false; + const coverUrl = document.querySelector("div.product-gallery")?.querySelector("img")?.getAttribute("src") ?? null; + if (coverUrl) { + getAttachment(coverUrl, this.attachmentMode, "cover-") + .then((coverClass) => { + additionalMetadate.cover = coverClass; + }) + .catch((error) => log.error(error)); + } + const chapters: Chapter[] = []; + let chapterNumber = 0; + let sectionName:string|null = null; + let sectionNumber = 0; + let sectionChapterNumber = 0; + function getAName(aElem: HTMLElement) { + return aElem.querySelector("p")?.innerHTML.trim() ?? aElem?.innerText.trim(); + } + const sectionList = document.querySelectorAll('#chapterList details'); + if (sectionList) { + sectionList.forEach((sectionElem) => { + sectionName = (sectionElem.querySelector('summary strong') as HTMLElement)?.innerText.trim() ?? null; + const aList = sectionElem.querySelectorAll('a'); + sectionNumber++; + sectionChapterNumber = 0; + aList.forEach((aElem) => { + const chapterUrl = (aElem as HTMLAnchorElement).href; + const chapterName = getAName(aElem as HTMLElement); + chapterNumber++; + sectionChapterNumber++; + chapters.push(new Chapter({ + bookUrl, + bookname, + chapterUrl, + chapterNumber, + chapterName, + isVIP, + isPaid, + sectionName, + sectionNumber, + sectionChapterNumber, + chapterParse: this.chapterParse, + charset: this.charset, + options: {}, + })); + }); + }); + } else { + const aList = document.querySelectorAll('#chapterList a'); + aList.forEach((aElem) => { + const chapterUrl = (aElem as HTMLAnchorElement).href; + const chapterName = getAName(aElem as HTMLElement); + chapterNumber++; + sectionChapterNumber++; + chapters.push(new Chapter({ + bookUrl, + bookname, + chapterUrl, + chapterNumber, + chapterName, + isVIP, + isPaid, + sectionName, + sectionNumber, + sectionChapterNumber, + chapterParse: this.chapterParse, + charset: this.charset, + options: {}, + })); + }); + } + + return new Book({ + bookUrl, + bookname, + author, + introduction, + introductionHTML, + additionalMetadate, + chapters, + }); + } + public async chapterParse( + chapterUrl: string, + chapterName: string | null, + isVIP: boolean, + isPaid: boolean, + charset: string, + options: object + ) { + const doc = await getHtmlDOM(chapterUrl, charset); + const content = doc.querySelector('.forum-content') as HTMLElement; + if (content) { + rm('h3', true, content); + rm('footer', true, content); + const { dom, text, images } = await cleanDOM(content, "TM"); + return { + chapterName, + contentRaw: content, + contentText: text, + contentHTML: dom, + contentImages: images, + additionalMetadate: null, + }; + } else { + return { + chapterName, + contentRaw: null, + contentText: null, + contentHTML: null, + contentImages: [], + additionalMetadate: null, + }; + } + } +}