Skip to content

Commit

Permalink
支持飘天文学网
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenSheiBot authored and yingziwu committed Mar 13, 2024
1 parent e9c8231 commit b10b0d3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ EPUB 文件请使用相应阅读器阅读。
| [新笔趣阁](https://www.ibiquge.la/) ||| |
| [69 书吧](https://www.69shu.com/) ||| |
| [笔下文学](https://www.ywggzy.com/) ||| |
| [飘天文学](https://www.ptwxz.net/) ||| |
| [飘天文学网](https://www.piaotia.com/) ||| |
| [红袖招](https://hongxiuzhao.me/) ||| |
| [38 看书](https://www.mijiashe.com/) ||| |
| [天天看小说](https://www.ttkan.co/) ||| |
Expand Down
3 changes: 1 addition & 2 deletions src/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@
"*://new-read.readmoo.com/mooreader/*",
"*://www.iqingguo.com/book/detail/?id=*",
"*://www.ywggzy.com/bxwx/*/",
"*://www.ptwxz.net/*/",
"*://www.ptwxz.net/list/*/",
"*://www.piaotia.com/html/*",
"*://www.mbtxt.la/go/*/",
"*://m.kuangguwenhua.com/bqg/*/",
"*://m.kuangguwenhua.com/bqg/11365/index_*.html",
Expand Down
4 changes: 2 additions & 2 deletions src/router/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ export async function getRule(): Promise<BaseRuleClass> {
ruleClass = novelup();
break;
}
case "www.ptwxz.net": {
case "www.piaotia.com": {
const { ptwxz } = await import(
"../rules/onePageWithMultiIndexPage/ptwxz"
"../rules/onePage/original/ptwxz"
);
ruleClass = ptwxz();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/router/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function getUI(): () => UIObject {
}
};
}
case "www.ptwxz.net": {
case "www.piaotia.com": {
return () => {
if (document.location.pathname.startsWith("/list/")) {
return {
Expand Down
61 changes: 61 additions & 0 deletions src/rules/onePage/original/ptwxz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { mkRuleClass } from "../template";

export const ptwxz = () =>
mkRuleClass({
bookUrl: document.location.href,
bookname:
document.querySelector("h1")?.innerText.trim().replace('最新章节', '') ?? "",
author:
document.querySelector('.list')?.textContent?.split(' \u00A0')[0]?.replace('作者:', '')?.trim() ?? "",
introDom: document.querySelector<HTMLDivElement>("#intro") ?? undefined,
introDomPatch: (dom) => dom,
coverUrl:
document.location.href.replace(/(https:\/\/www\.piaotia\.com)\/html\/(\d+)\/(\d+)(\/index.html)?\/?$/, '$1/files/article/image/$2/$3/$3s.jpg'),
getAName: (aElem) => (aElem as HTMLElement).innerText.trim(),
aList: document.querySelectorAll('ul > li > a'),
getContent: (dom) => dom.body,
contentPatch: (dom) => {
const title = dom.querySelector('h1')?.textContent?.trim() ?? '';

// Find the <table> and <div class='bottomlink'> elements within the provided root element
const table = dom.querySelector('table');
const bottomLink = dom.querySelector("div.bottomlink");

// Check if the elements exist
if (!table || !bottomLink) {
throw new Error('The required elements are not found in the DOM.');
}

// The final HTML content string
let content = '';

// Process the DOM nodes
let currentNode = table.nextSibling;
while (currentNode && currentNode !== bottomLink) {
// If currentNode is a text node or not a <table> or <div>, process it
if (currentNode.nodeType === Node.TEXT_NODE || (currentNode.nodeType === Node.ELEMENT_NODE && currentNode.nodeName.toLowerCase() !== 'table' && currentNode.nodeName.toLowerCase() !== 'div')) {
let textContent = currentNode.textContent || '';
if (currentNode.nodeType === Node.ELEMENT_NODE && currentNode.nodeName.toLowerCase() === 'br') {
// Replace <br> with newlines
textContent = '\n';
}

// Split the text contents at newlines and wrap each line in <p> tags
textContent.split('\n').forEach((line) => {
const trimmedLine = line.trim();
if (trimmedLine && title !== trimmedLine) {
content += `<p>${trimmedLine}</p>`;
}
});
}
// Move to the next sibling node
currentNode = currentNode.nextSibling;
}

// Create a new div and set its innerHTML to the processed content
const divElement = document.createElement('div');
divElement.innerHTML = content;

return divElement;
}
});
59 changes: 0 additions & 59 deletions src/rules/onePageWithMultiIndexPage/ptwxz.ts

This file was deleted.

0 comments on commit b10b0d3

Please sign in to comment.