Skip to content

Commit

Permalink
fix #662
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0206 committed Dec 24, 2024
1 parent ccad0a1 commit 8d1f1a7
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"incompatible": ["Internet Explorer"],
"match": [
"*://www.lzdzw.com/*/*.html",
"*://www.60ksw.com/*/*/*/index.html",
"*://czbooks.net/n/*",
"*://book.qq.com/book-detail/*",
Expand Down
5 changes: 5 additions & 0 deletions src/router/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ export async function getRule(): Promise<BaseRuleClass> {
ruleClass = i60ksw();
break;
}
case "www.lzdzw.com": {
const { lzdzw } = await import("../rules/special/reprint/lzdzw");
ruleClass = lzdzw;
break;
}
case "czbooks.net": {
const { czbooks } = await import("../rules/onePage/czbooks");
ruleClass = czbooks();
Expand Down
133 changes: 133 additions & 0 deletions src/rules/special/reprint/lzdzw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { getAttachment } from "../../../lib/attachments";
import { cleanDOM } from "../../../lib/cleanDOM";
import { rm, rm2 } from "../../../lib/dom";
import { ggetHtmlDOM, getFrameContentEvent } from "../../../lib/http";
import { introDomHandle } from "../../../lib/rule";
import { log } from "../../../log";
import { Book, BookAdditionalMetadate } from "../../../main/Book";
import { Chapter } from "../../../main/Chapter";
import { BaseRuleClass, ChapterParseObject } from "../../../rules";

export class lzdzw extends BaseRuleClass {
public constructor() {
super();
}

public async bookParse(): Promise<Book> {
const bookUrl = document.location.href;
const bookname = (
document.querySelector(".book_info h1") as HTMLElement
).innerText.trim();
const author = (
document.querySelector(".book_info div.options li a") as HTMLAnchorElement
).innerText.trim();
const intro = (
document.querySelector("#intro_pc") as HTMLElement
);
rm("strong", true, intro);
rm2(["您要是觉得《","》还不错的话请不要忘记向您QQ群和微博微信里的朋友推荐哦!"], intro);
const [introduction, introductionHTML] = await introDomHandle(intro);
const additionalMetadate: BookAdditionalMetadate = {};
const coverUrl = (document.querySelector("img.img-thumbnail") as HTMLImageElement).src;
getAttachment(coverUrl, this.attachmentMode, "cover-")
.then((coverClass) => {
additionalMetadate.cover = coverClass;
})
.catch((error) => log.error(error));
const chapters: Chapter[] = [];
const match = bookUrl.match(/\/(\d+)\.html/);
function getAList(doc: Document) {
return doc.querySelectorAll(".book_list a");
}
const ALists: Element[] = [];
if (match) {
const id = match[1];
const url = `https://www.lzdzw.com/book/${id}/1/`;
const contentList = await ggetHtmlDOM(url).then((doc) => doc.querySelectorAll(".page-item option"));
for (const a of Array.from(contentList)) {
const url = "https://www.lzdzw.com/" + a.getAttribute("value");
const dom = await ggetHtmlDOM(url);
const AList = getAList(dom);
for (const a of Array.from(AList)) {
ALists.push(a);
}
}
let chapterNumber = 0;
for (const a of ALists) {
chapterNumber++;
const chapterName = (a as HTMLElement).innerText;
const chapterUrl = (a as HTMLAnchorElement).href;
const chapter = new Chapter({
bookUrl,
bookname,
chapterUrl: chapterUrl,
chapterNumber: chapterNumber,
chapterName: chapterName,
isVIP: false,
isPaid: false,
sectionName: null,
sectionNumber: null,
sectionChapterNumber: null,
chapterParse: this.chapterParse.bind(this),
charset: this.charset,
options: {},
});
chapters.push(chapter);
}
} else {
throw new Error("获取小说ID失败");
}

return new Book({
bookUrl,
bookname,
author,
introduction,
introductionHTML,
additionalMetadate,
chapters,
});
}
public async chapterParse(
chapterUrl: string,
chapterName: string | null,
isVIP: boolean,
isPaid: boolean | null,
charset: string,
options: Record<string, any>
): Promise<ChapterParseObject> {
const content = document.createElement("div");
const doc = await getFrameContentEvent(chapterUrl);
function appendcontent(dom: Document | null) {
if (!dom) return;
const br = document.createElement("br");
const ps = dom.querySelectorAll("#novelcontent p");
for (const p of Array.from(ps)) {
content.appendChild(p);
content.appendChild(br);
}
}
appendcontent(doc);
const url = chapterUrl.replace(".html", "");
let i = 0;
while (i< 10000) {
i++;
const newUrl = url + '_' + i + ".html";
const dom = await ggetHtmlDOM(newUrl);
if (dom.title.match("第1页"))
break;
appendcontent(dom);
}
rm2(["请关闭浏览器阅读模式后查看本章节,否则将出现无法翻页或章节内容丢失等现象。"], content);
const text = content.innerText;
return {
chapterName,
contentRaw: content,
contentText: text,
contentHTML: content,
contentImages: null,
additionalMetadate: null,
};
}
}

0 comments on commit 8d1f1a7

Please sign in to comment.