Files
RSSHub/lib/routes/69shu/article.ts
T
dependabot[bot]andTony 417ab04f06 chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 (#22310)
* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 68.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* style: fix no-useless-coercion

* style: fix prefer-boolean-return

* style: fix no-useless-logical-operand

* style: fix prefer-single-replace

* style: fix consistent-conditional-object-spread

* style: fix no-useless-else

* style: fix prefer-unicode-code-point-escapes

* style: fix operator-assignment

* style: fix prefer-continue

* style: fix prefer-math-constants

* style: fix prefer-hoisting-branch-code

* style: fix prefer-array-slice

* style: fix consistent-class-member-order

* style: fix no-return-array-push

* style: fix prefer-promise-with-resolvers

* style: fix no-array-concat-in-loop

* style: fix no-loop-iterable-mutation

* style: fix no-invalid-argument-count

* style: fix no-duplicate-if-branches

* style: fix prefer-else-if

* style: fix no-unreadable-for-of-expression

* style: fix logical-assignment-operators

* style: fix default-export-style

* style: revert false positve in prefer-type-literal-last in #22274

* style: fix arrow-body-style

* style: add v68 recommended preset

* style: refactor GraphQL queries to use template literals for better readability

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-20 23:11:27 +08:00

104 lines
3.2 KiB
TypeScript

import { load } from 'cheerio';
import type { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
export const route: Route = {
path: '/article/:id',
name: '章节',
url: 'www.69shuba.cx',
maintainers: ['eternasuno'],
example: '/69shu/article/47117',
parameters: { id: '小说 id, 可在对应小说页 URL 中找到' },
categories: ['reading'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.69shuba.cx/book/:id.htm'],
target: '/article/:id',
},
],
handler: async (ctx) => {
const { id } = ctx.req.param();
const link = `https://www.69shuba.cx/book/${id}.htm`;
const html = await get(link);
const $ = load(html);
const item = await Promise.all(
$('.qustime li>a')
.toArray()
.map((chapter) => createItem(chapter.attribs.href))
);
return {
title: $('h1>a').text(),
description: $('.navtxt>p:first-of-type').text(),
link,
item,
image: $('.bookimg2>img').attr('src'),
author: $('.booknav2>p:first-of-type>a').text(),
language: 'zh-cn',
};
},
};
const createItem = (url: string) =>
cache.tryGet(url, async () => {
const html = await get(url);
const $ = load(html);
const { articleid, chapterid, chaptername } = parseObject(/bookinfo\s?=\s?\{[\s\S]+?\}/, $('head>script:not([src])').text());
const decryptionMap = parseObject(/_\d+\s?=\s?\{[\s\S]+?\}/, $('.txtnav+script').text());
return {
title: chaptername,
description: decrypt($('.txtnav').html() || '', articleid, chapterid, decryptionMap),
link: url,
};
}) as Promise<DataItem>;
const get = async (url: string, encoding = 'gbk') => new TextDecoder(encoding).decode(await ofetch(url, { responseType: 'arrayBuffer' }));
const parseObject = (reg: RegExp, str: string): Record<string, string> => {
const obj = {};
const match = reg.exec(str);
if (match) {
const matchedLines = match[0].matchAll(/(\w+):\s?["']?([\s\S]+?)["']?[\n,}]/g);
for (const line of matchedLines) {
obj[line[1]] = line[2];
}
}
return obj;
};
const decrypt = (txt: string, articleid: string, chapterid: string, decryptionMap: Record<string, string>) => {
if (!txt || txt.length < 10) {
return txt;
}
const lineMap = {};
const articleKey = Number(articleid) + 3_061_711;
const chapterKey = Number(chapterid) + 3_421_001;
for (const [key, value] of Object.entries(decryptionMap)) {
lineMap[(Number(key) ^ chapterKey) - articleKey] = (Number(value) ^ chapterKey) - articleKey;
}
return txt
.replaceAll(/\u{2003}|\n/gu, '')
.split('<br><br>')
.flatMap((line, index, array) => {
const mapped = lineMap[index];
return (mapped ? array[mapped] : line).split('<br>');
})
.slice(1, -2)
.join('<br><br>');
};