Files
RSSHub/lib/routes/dcfever/utils.tsx
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

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

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

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

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-09 00:08:15 +08:00

133 lines
4.4 KiB
TypeScript

import { load } from 'cheerio';
import { raw } from 'hono/html';
import { renderToString } from 'hono/jsx/dom/server';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const baseUrl = 'https://www.dcfever.com';
const renderTradeDescription = (info, description, photo) =>
renderToString(
<>
<h2>{info.find('.trading_item_title').text()}</h2>
{info.find('.trading_item_type_tag').text()} {info.find('.trading_item_price').text()}
<br />
<table>
<tr>
<th>賣家</th>
<td>{info.find('.clearfix .content').eq(0).text()}</td>
</tr>
<tr>
<th>查詢次數</th>
<td>{info.find('.clearfix .content').eq(1).text()}</td>
</tr>
<tr>
<th>瀏覽次數</th>
<td>{info.find('.clearfix .content').eq(2).text()}</td>
</tr>
<tr>
<th>刊登日期</th>
<td>{info.find('.clearfix .content').eq(3).text()}</td>
</tr>
<tr>
<th>最後更新</th>
<td>{info.find('.clearfix .content').eq(4).text()}</td>
</tr>
<tr>
<th>刊登期至</th>
<td>{info.find('.clearfix .content').eq(5).text()}</td>
</tr>
<tr>
<th>刊登狀態</th>
<td>{info.find('.clearfix .content').eq(6).text()}</td>
</tr>
</table>
<br />
{description ? <>{raw(description)}</> : null}
<br />
<br />
{photo ? <>{raw(photo)}</> : null}
</>
);
const parseItem = (item) =>
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
const content = $('div[itemprop="articleBody"], .column_article_content_html');
const pageLinks = $('.article_multi_page a')
.not('.selected')
.toArray()
.map((i) => ({ link: new URL($(i).attr('href'), item.link).href }));
if (pageLinks.length) {
const pages = await Promise.all(
pageLinks.map(async (pageLink) => {
const response = await ofetch(pageLink.link);
const $ = load(response);
return $('div[itemprop="articleBody"]').html();
})
);
content.append(pages);
}
content.find('img').each((_, e) => {
if (e.attribs.src?.includes('?')) {
e.attribs.src = e.attribs.src.split('?', 1)[0];
}
});
content.find('p a').each((_, e) => {
e = $(e);
if (e.text().startsWith('下一頁為')) {
e.remove();
}
});
content.find('iframe').each((_, e) => {
e = $(e);
if (e.attr('src').startsWith('https://www.facebook.com/plugins/like.php')) {
e.remove();
}
});
item.description = content.html();
item.pubDate = parseDate($('meta[property="article:published_time"]').attr('content'));
return item;
});
const parseTradeItem = (item) =>
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
const photoSelector = $('#trading_item_section .description')
.contents()
.filter((_, e) => e.type === 'comment')
.toArray()
.map((e) => e.data)
.join('');
const $photo = load(photoSelector, null, false);
$photo('.selector_text').remove();
$photo('.selector_image_div').each((_, div) => {
delete div.attribs.onclick;
});
$photo('.desktop_photo_selector img').each((_, img) => {
if (img.attribs.src.endsWith('_sqt.jpg')) {
img.attribs.src = img.attribs.src.replace('_sqt.jpg', '.jpg');
}
});
item.description = renderTradeDescription($('.info_col'), $('.description_text').html(), $photo('.desktop_photo_selector').html());
return item;
});
export { baseUrl, parseItem, parseTradeItem };