/
index.ts
88 lines (85 loc) · 2.92 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/:uid',
categories: ['anime'],
example: '/xmanhua/73xm',
parameters: { uid: '漫画 id,在浏览器中可见,例如鬼灭之刃对应的 id 为 `73xm`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['xmanhua.com/:uid'],
},
],
name: '最新动态',
maintainers: ['Ye11'],
handler,
};
async function handler(ctx) {
const uid = ctx.req.param('uid');
const host = 'https://xmanhua.com';
const url = `https://xmanhua.com/${uid}/`;
const response = await got({
method: 'get',
url,
headers: {
Referer: host,
},
});
const data = response.data;
const $ = load(data);
const list = $('div #chapterlistload').find('.detail-list-form-item');
// 作者
const autherName = $('body > div.detail-info-1 > div > div > p.detail-info-tip > span:nth-child(1)').text().split(':')[1];
// 检查漫画是否已经完结
const finished_text = $('div.detail-list-form-title').clone().children().remove().end().text();
let finished = false;
let newOneDate = finished_text.split(',')[1];
if (newOneDate.includes('月') && newOneDate.includes('號')) {
const month = Number.parseInt(newOneDate.split('月')[0]);
const date = Number.parseInt(newOneDate.split('月')[1].split('號')[0]);
const year = new Date().getFullYear();
newOneDate = new Date(year, month - 1, date + 1);
} else {
newOneDate = new Date(newOneDate);
newOneDate.setDate(newOneDate.getDate() + 1);
}
if (finished_text.includes('已完結') || finished_text.includes('已完结')) {
finished = true;
}
// 最新一话的地址
const updatedOne = $('div.detail-list-form-title span.s a').attr('href');
const items = list
.map((index, item) => {
item = $(item);
const itemTitle = item.text();
const itemUrl = item.attr('href');
const itemDate = itemUrl === updatedOne ? parseDate(newOneDate) : '';
return {
title: itemTitle,
link: host + itemUrl,
auther: autherName,
pubDate: itemDate,
guid: host + itemUrl,
};
})
.get();
const name = $('body > div.detail-info-1 > div > div > p.detail-info-title').text();
const description_ = finished ? '已完结' : '连载中';
return {
title: `x漫画 ${name}`,
link: `https://xmanhua.com/${uid}`,
description: description_,
allowEmpty: true,
item: items,
};
}