Skip to content

Commit

Permalink
fix #711
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0206 committed Dec 19, 2024
1 parent 2674f98 commit a13c927
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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文件可能会遇到问题。<br> 解决办法: <br> 按F12 弹出开发工具-> 转到网络页(Network)->按ctrl+R重新加载->找到core.js(链接为https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js )->右键选择点击“屏蔽请求网址”->重新刷新网页即可正常下载。 |
<details>
<summary>点击查看全部支持网站</summary>

Expand Down
4 changes: 2 additions & 2 deletions src/router/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ export async function getRule(): Promise<BaseRuleClass> {
}
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 **/
Expand Down
37 changes: 0 additions & 37 deletions src/rules/onePage/original/esjzone.ts

This file was deleted.

149 changes: 149 additions & 0 deletions src/rules/special/original/esjzone.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
}
}

0 comments on commit a13c927

Please sign in to comment.