* chore(deps-dev): bump eslint-plugin-unicorn from 65.0.1 to 66.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 65.0.1 to 66.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v65.0.1...v66.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 66.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix unicorn-js/prefer-url-href * style: oxlint disable * style: fix unicorn-js/no-useless-else * style: no-unsafe-string-replacement * style: fix no-duplicate-loops * style: fix prefer-number-is-safe-integer * style: fix prefer-single-array-predicate * style: fix no-object-methods-with-collections * style: fix no-useless-boolean-cast * style: fix no-useless-template-literals * style: fix no-negated-array-predicate * style: fix prefer-direct-iteration * style: fix consistent-optional-chaining * style: fix prefer-simple-sort-comparator * style: fix prefer-global-number-constants * style: fix prefer-type-literal-last * style: fix require-array-sort-compare. * style: fix prefer-early-return * style: fix prefer-short-arrow-method * style: fix prefer-array-from-map * style: fix prefer-scoped-selector * style: fix no-global-object-property-assignment * style: fix no-unnecessary-global-this * style: fix no-unreadable-object-destructuring * style: fix no-invalid-argument-count * style: fix prefer-smaller-scope * style: fix prefer-iterator-to-array. * style: fix prefer-object-iterable-methods * style: fix typo * style: fix max-nested-calls * style: fix no-incorrect-template-string-interpolation * style: fix no-break-in-nested-loop * style: fix prefer-await * style: fix no-computed-property-existence-check * style: fix prefer-number-coercion * style: fix no-empty-file * style: update eslint unicorn v66 recommended preset * style: add unicorn/prefer-spread to oxlint-disable comments * style: fix no-array-reduce * style: delete github/no-then as it's covered by unicorn/prefer-await --------- 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>
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import * as cheerio from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import ofetch from '@/utils/ofetch';
|
|
|
|
const jjmhw = 'http://www.jjmhw.cc';
|
|
|
|
const getLatestAddress = () =>
|
|
cache.tryGet('freexcomic:getLatestAddress', async () => {
|
|
const portalResponse = await ofetch('https://www.freexcomic.com');
|
|
const $portal = cheerio.load(portalResponse);
|
|
const portalUrl = new URL($portal('.alert-btn').attr('href')).href.replace('http:', 'https:');
|
|
|
|
const addressList = await ofetch(portalUrl);
|
|
const $address = cheerio.load(addressList);
|
|
|
|
return $address('p.ta-c.mb10 a')
|
|
.toArray()
|
|
.map((item) => $address(item).attr('href'));
|
|
});
|
|
|
|
const handler = async (ctx) => {
|
|
const { id } = ctx.req.param();
|
|
const limit = Number(ctx.req.query('limit')) || 10;
|
|
const addresses = (await getLatestAddress()) as string[];
|
|
const link = `${addresses[0]}book/${id}`;
|
|
|
|
const response = await ofetch(link);
|
|
const $ = cheerio.load(response);
|
|
|
|
const list = $('#detail-list-select > li > a')
|
|
.toArray()
|
|
.toReversed()
|
|
.slice(0, limit)
|
|
.map((item) => {
|
|
const $item = $(item);
|
|
return {
|
|
title: $item.text(),
|
|
link: new URL($item.attr('href'), addresses[Math.floor(Math.random() * addresses.length)]).href,
|
|
guid: new URL($item.attr('href'), jjmhw).href,
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
const response = await ofetch(item.link);
|
|
const $ = cheerio.load(response);
|
|
|
|
const comicpage = $('.comicpage');
|
|
comicpage.find('img').each((_, ele) => {
|
|
ele.attribs.src = ele.attribs['data-original'];
|
|
});
|
|
|
|
item.description = comicpage.html();
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: `漫小肆 ${$('div.info > h1').text()}`,
|
|
link,
|
|
description: `漫小肆 ${$('div.info .content span span').text()}`,
|
|
image: $('.banner_detail .cover img').attr('src'),
|
|
item: items,
|
|
};
|
|
};
|
|
|
|
export const route: Route = {
|
|
path: '/book/:id',
|
|
example: '/freexcomic/book/90',
|
|
parameters: { id: '漫画id,漫画主页的地址栏中' },
|
|
radar: [
|
|
{
|
|
source: ['www.jjmhw.cc/book/:id'],
|
|
},
|
|
],
|
|
name: '漫画更新',
|
|
maintainers: ['junfengP'],
|
|
handler,
|
|
url: 'www.jjmhw.cc',
|
|
features: {
|
|
nsfw: true,
|
|
},
|
|
};
|