From ee32cffa05d78f2cc52fbf35e10d045f55868198 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 8 Jul 2026 19:47:09 +0800 Subject: [PATCH] refactor: named import cheerio.load (#22477) --- lib/routes/12371/zxfb.ts | 6 +++--- lib/routes/afr/utils.ts | 6 +++--- lib/routes/blogread/index.ts | 4 ++-- lib/routes/bluestacks/release.ts | 6 +++--- lib/routes/cas/mesalab/kb.ts | 6 +++--- lib/routes/chiphell/portal.ts | 8 ++++---- lib/routes/deepseek/news.ts | 10 ++++++---- lib/routes/dxy/utils.ts | 4 ++-- lib/routes/economist/espresso.ts | 4 ++-- lib/routes/espn/news.tsx | 4 ++-- lib/routes/esquirehk/tag.tsx | 4 ++-- lib/routes/f-droid/apprelease.ts | 4 ++-- lib/routes/famitsu/category.tsx | 4 ++-- lib/routes/fanqienovel/page.ts | 4 ++-- lib/routes/freexcomic/book.ts | 10 +++++----- lib/routes/guokr/utils.ts | 4 ++-- lib/routes/hket/index.tsx | 6 +++--- lib/routes/hko/weather.ts | 6 +++--- lib/routes/hypergryph/arknights/news.ts | 6 +++--- lib/routes/hypergryph/endfield/news.ts | 4 ++-- lib/routes/imdb/chart.tsx | 4 ++-- lib/routes/juejin/utils.ts | 6 +++--- lib/routes/kpmg/insights.tsx | 4 ++-- lib/routes/kurogames/wutheringwaves/news.ts | 4 ++-- lib/routes/lianxh/index.ts | 4 ++-- lib/routes/luogu/user-article.ts | 4 ++-- lib/routes/matters/tags.ts | 4 ++-- lib/routes/mingpao/index.tsx | 6 +++--- lib/routes/missav/new.tsx | 4 ++-- lib/routes/nmc/weatheralarm.ts | 4 ++-- lib/routes/patreon/feed.tsx | 4 ++-- lib/routes/psnine/game.ts | 4 ++-- lib/routes/psnine/index.ts | 4 ++-- lib/routes/psnine/node.ts | 6 +++--- lib/routes/psnine/shuzhe.ts | 4 ++-- lib/routes/psnine/trade.ts | 4 ++-- lib/routes/qstheory/index.ts | 4 ++-- lib/routes/qstheory/magazine.ts | 6 +++--- lib/routes/qstheory/utils.ts | 4 ++-- lib/routes/sega/maimaidx.ts | 10 ++++++---- lib/routes/sega/pjsekai.ts | 4 ++-- lib/routes/sohu/mobile.ts | 13 +++++++------ lib/routes/sohu/mp.tsx | 6 +++--- lib/routes/spankbang/new-videos.tsx | 4 ++-- lib/routes/t66y/index.ts | 4 ++-- lib/routes/t66y/post.ts | 11 ++++++----- lib/routes/t66y/utils.ts | 4 ++-- lib/routes/telegram/blog.ts | 6 +++--- lib/routes/thepaper/user.ts | 4 ++-- lib/routes/tongli/news.ts | 6 +++--- lib/routes/vertikal/latest.ts | 6 +++--- lib/routes/wired/tag.ts | 8 ++++---- lib/routes/yenpress/series.tsx | 6 +++--- lib/routes/youtube/api/google.ts | 4 ++-- lib/routes/zaker/channel.ts | 4 ++-- lib/routes/zaker/focus.ts | 4 ++-- lib/routes/zaker/utils.ts | 20 +++++++++++++------- lib/routes/zhizhuan100/report.ts | 6 +++--- 58 files changed, 168 insertions(+), 156 deletions(-) diff --git a/lib/routes/12371/zxfb.ts b/lib/routes/12371/zxfb.ts index ff1ac554a..77ee6a354 100644 --- a/lib/routes/12371/zxfb.ts +++ b/lib/routes/12371/zxfb.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -14,7 +14,7 @@ const handler = async (ctx) => { const currentUrl = `${rootUrl}${category}/`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const pattern = /item=(\[\{.*?\}\]);/; const newsList = JSON.parse($('script[language="javascript"]').text().match(pattern)?.[1].replaceAll("'", '"') || '[]'); @@ -29,7 +29,7 @@ const handler = async (ctx) => { topNewsList.map((item) => cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); item.description = $('.word').html(); diff --git a/lib/routes/afr/utils.ts b/lib/routes/afr/utils.ts index f56d36248..d51f68ff7 100644 --- a/lib/routes/afr/utils.ts +++ b/lib/routes/afr/utils.ts @@ -1,10 +1,10 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import ofetch from '@/utils/ofetch'; export const getItem = async (item) => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const reduxState = JSON.parse($('script#__REDUX_STATE__').text().replaceAll(':undefined', ':null').match('__REDUX_STATE__=(.*);')?.[1] || '{}'); @@ -29,7 +29,7 @@ export const getItem = async (item) => { }; const renderArticle = (asset, link: string) => { - const $ = cheerio.load(asset.body, null, false); + const $ = load(asset.body, null, false); $('x-placeholder').each((_, el) => { const $el = $(el); const id = $el.attr('id'); diff --git a/lib/routes/blogread/index.ts b/lib/routes/blogread/index.ts index 3827985a2..8ccfff9c0 100644 --- a/lib/routes/blogread/index.ts +++ b/lib/routes/blogread/index.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import got from '@/utils/got'; @@ -23,7 +23,7 @@ async function handler() { method: 'get', url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const resultItem = $('.media') .toArray() .map((elem) => { diff --git a/lib/routes/bluestacks/release.ts b/lib/routes/bluestacks/release.ts index e249a296c..d76a1a7b1 100644 --- a/lib/routes/bluestacks/release.ts +++ b/lib/routes/bluestacks/release.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -44,7 +44,7 @@ async function handler() { const res = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const $ = cheerio.load(res); + const $ = load(res); const list = $('div h3 a') .toArray() @@ -68,7 +68,7 @@ async function handler() { waitUntil: 'domcontentloaded', }); const res = await page.evaluate(() => document.documentElement.innerHTML); - const $ = cheerio.load(res); + const $ = load(res); await page.close(); item.description = $('div.article__body').html(); diff --git a/lib/routes/cas/mesalab/kb.ts b/lib/routes/cas/mesalab/kb.ts index 35bebdfa8..4e9da91b3 100644 --- a/lib/routes/cas/mesalab/kb.ts +++ b/lib/routes/cas/mesalab/kb.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -35,7 +35,7 @@ async function handler() { const url = `${homepage}/f/article/articleList?pageNo=1&pageSize=15&createTimeSort=DESC`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const articles = $('.aw-item').toArray(); const items = await Promise.all( @@ -46,7 +46,7 @@ async function handler() { return cache.tryGet(link, async () => { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); return { title, author: $('.user_name').text(), diff --git a/lib/routes/chiphell/portal.ts b/lib/routes/chiphell/portal.ts index 752de923a..b2a3075ec 100644 --- a/lib/routes/chiphell/portal.ts +++ b/lib/routes/chiphell/portal.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import type { Route } from '@/types'; @@ -12,7 +12,7 @@ const handler = async (ctx: Context) => { const url = `https://www.chiphell.com/portal.php?mod=list&catid=${catId}`; const response = await ofetch(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('dl.cl') .toArray() @@ -32,7 +32,7 @@ const handler = async (ctx: Context) => { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('#article_content div br').parent().remove(); let description = $('#article_content').html(); @@ -46,7 +46,7 @@ const handler = async (ctx: Context) => { }) .slice(0, -1); const responses = await Promise.all(urls.map((url) => ofetch(url))); - const $pages = responses.map((item) => cheerio.load(item)); + const $pages = responses.map((item) => load(item)); const contents = $pages.map(($item) => { $item('#article_content div br').parent().remove(); return $item('#article_content').html(); diff --git a/lib/routes/deepseek/news.ts b/lib/routes/deepseek/news.ts index 0f6de7af3..999d2eb26 100644 --- a/lib/routes/deepseek/news.ts +++ b/lib/routes/deepseek/news.ts @@ -1,4 +1,6 @@ -import * as cheerio from 'cheerio'; +import type { CheerioAPI } from 'cheerio'; +import { load } from 'cheerio'; +import type { Element } from 'domhandler'; import type { Data, DataItem, Route } from '@/types'; import cache from '@/utils/cache'; @@ -13,11 +15,11 @@ const ARTICLE_TITLE_SELECTOR = ARTICLE_CONTENT_SELECTOR + ' > h1'; // 获取消息列表 / get article list const fetchPageContent = async (url: string) => { const response = await ofetch(url); - return cheerio.load(response); + return load(response); }; // 提取正文内容 / extract article content -const extractArticleInfo = ($article: cheerio.Root, pageURL: string) => { +const extractArticleInfo = ($article: CheerioAPI, pageURL: string) => { const contentElement = $article(ARTICLE_CONTENT_SELECTOR); const title = $article(ARTICLE_TITLE_SELECTOR).text(); $article(ARTICLE_TITLE_SELECTOR).remove(); // 移除标题,避免重复 / remove title to avoid duplication @@ -31,7 +33,7 @@ const parseDateString = (dateString: string) => { }; // 创建消息 / create article -const createDataItem = (item: cheerio.Element, $: cheerio.Root): Promise => { +const createDataItem = (item: Element, $: CheerioAPI): Promise => { const $item = $(item); const link = $item.find('a').attr('href'); const dateString = $item.find('a').text().split(' ').at(-1); diff --git a/lib/routes/dxy/utils.ts b/lib/routes/dxy/utils.ts index 844531d51..0663a0a56 100644 --- a/lib/routes/dxy/utils.ts +++ b/lib/routes/dxy/utils.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import CryptoJS from 'crypto-js'; import cache from '@/utils/cache'; @@ -53,7 +53,7 @@ const getPost = (item) => throw new Error(post.message); } - const $ = cheerio.load(post.data.body, null, false); + const $ = load(post.data.body, null, false); $('img').each((_, img) => { img = $(img); diff --git a/lib/routes/economist/espresso.ts b/lib/routes/economist/espresso.ts index ab5287a68..bce577e32 100644 --- a/lib/routes/economist/espresso.ts +++ b/lib/routes/economist/espresso.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import sanitizeHtml from 'sanitize-html'; import xxhash from 'xxhash-wasm'; @@ -42,7 +42,7 @@ async function handler() { link, async () => { const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); return JSON.parse($('script#__NEXT_DATA__').text()); }, config.cache.routeExpire, diff --git a/lib/routes/espn/news.tsx b/lib/routes/espn/news.tsx index f97edced9..e57b6fd29 100644 --- a/lib/routes/espn/news.tsx +++ b/lib/routes/espn/news.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { renderToString } from 'hono/jsx/dom/server'; import type { Route } from '@/types'; @@ -112,7 +112,7 @@ export const route: Route = { }, }); - const $ = cheerio.load(article.content.story, null, false); + const $ = load(article.content.story, null, false); $('*').each((_, ele) => { if (junkPattern.test(ele.name)) { $(ele).remove(); diff --git a/lib/routes/esquirehk/tag.tsx b/lib/routes/esquirehk/tag.tsx index e15384ec2..fdf2e12e9 100644 --- a/lib/routes/esquirehk/tag.tsx +++ b/lib/routes/esquirehk/tag.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { destr } from 'destr'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -25,7 +25,7 @@ const handler = async (ctx) => { const response = await ofetch(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = [ ...$('div[class^="max-w-[100%]"] > div > div:nth-child(2) > a') .toArray() diff --git a/lib/routes/f-droid/apprelease.ts b/lib/routes/f-droid/apprelease.ts index aed38c6db..a6caf5866 100644 --- a/lib/routes/f-droid/apprelease.ts +++ b/lib/routes/f-droid/apprelease.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import got from '@/utils/got'; @@ -30,7 +30,7 @@ export const route: Route = { async function handler(ctx) { const { app } = ctx.req.param(); const { data: response } = await got(`https://f-droid.org/en/packages/${app}/`); - const $ = cheerio.load(response); + const $ = load(response); const appName = $('.package-title').find('h3').text().trim(); diff --git a/lib/routes/famitsu/category.tsx b/lib/routes/famitsu/category.tsx index a1f95b9c5..147b39798 100644 --- a/lib/routes/famitsu/category.tsx +++ b/lib/routes/famitsu/category.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -35,7 +35,7 @@ function getBuildId() { 'famitsu:buildId', async () => { const data = await ofetch(baseUrl); - const $ = cheerio.load(data); + const $ = load(data); const nextData = JSON.parse($('#__NEXT_DATA__').text()); return nextData.buildId; }, diff --git a/lib/routes/fanqienovel/page.ts b/lib/routes/fanqienovel/page.ts index 11fc5bf9d..99ad572f5 100644 --- a/lib/routes/fanqienovel/page.ts +++ b/lib/routes/fanqienovel/page.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import type { Data, Route } from '@/types'; @@ -71,7 +71,7 @@ async function handler(ctx: Context): Promise { const link = `https://fanqienovel.com/page/${bookId}`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const initialState = JSON.parse( $('script:contains("window.__INITIAL_STATE__")') diff --git a/lib/routes/freexcomic/book.ts b/lib/routes/freexcomic/book.ts index 76124a884..c974820cf 100644 --- a/lib/routes/freexcomic/book.ts +++ b/lib/routes/freexcomic/book.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -9,11 +9,11 @@ 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 $portal = 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); + const $address = load(addressList); return $address('p.ta-c.mb10 a') .toArray() @@ -27,7 +27,7 @@ const handler = async (ctx) => { const link = `${addresses[0]}book/${id}`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#detail-list-select > li > a') .toArray() @@ -46,7 +46,7 @@ const handler = async (ctx) => { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const comicpage = $('.comicpage'); comicpage.find('img').each((_, ele) => { diff --git a/lib/routes/guokr/utils.ts b/lib/routes/guokr/utils.ts index b6bc262ed..133f39b3a 100644 --- a/lib/routes/guokr/utils.ts +++ b/lib/routes/guokr/utils.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import cache from '@/utils/cache'; import got from '@/utils/got'; @@ -19,7 +19,7 @@ export const parseList = (result) => export const parseItem = (item) => cache.tryGet(item.link, async () => { const { data: res } = await got(`https://apis.guokr.com/minisite/article/${item.id}.json`); - const $ = cheerio.load(res.result.content); + const $ = load(res.result.content); $('#meta_content').remove(); $('div').each((_, elem) => { diff --git a/lib/routes/hket/index.tsx b/lib/routes/hket/index.tsx index fd762ae61..b1dcf60e3 100644 --- a/lib/routes/hket/index.tsx +++ b/lib/routes/hket/index.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { renderToString } from 'hono/jsx/dom/server'; import type { DataItem, Route } from '@/types'; @@ -137,7 +137,7 @@ async function handler(ctx) { const response = await ofetch(`${baseUrl}/${category}`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.main-listing-container div.listing-title > a') .toArray() @@ -185,7 +185,7 @@ async function handler(ctx) { } const response = await ofetch(item.link!); - const $ = cheerio.load(response); + const $ = load(response); item.category = $('.contentTags-container > .hotkey-container-wrapper > .hotkey-container > a') .toArray() diff --git a/lib/routes/hko/weather.ts b/lib/routes/hko/weather.ts index 0bd934b34..7205b762b 100644 --- a/lib/routes/hko/weather.ts +++ b/lib/routes/hko/weather.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; @@ -9,13 +9,13 @@ const handler = async () => { const pageUrl = 'https://www.weather.gov.hk/en/wxinfo/currwx/current.htm'; const data = await ofetch(url); - const $ = cheerio.load(data, { + const $ = load(data, { xmlMode: true, }); const description = $('item').first().find('description'); - const $$ = cheerio.load(description.text()); + const $$ = load(description.text()); const items = $$('table tr') .toArray() diff --git a/lib/routes/hypergryph/arknights/news.ts b/lib/routes/hypergryph/arknights/news.ts index 01fe51023..357bf3228 100644 --- a/lib/routes/hypergryph/arknights/news.ts +++ b/lib/routes/hypergryph/arknights/news.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { config } from '@/config'; import type { Route } from '@/types'; @@ -80,7 +80,7 @@ async function handler(ctx) { 'hypergryph:arknights:news', async () => { const response = await ofetch('https://ak.hypergryph.com/news'); - const $ = cheerio.load(response); + const $ = load(response); const renderData = JSON.parse( $('script:contains("initialData")') .first() @@ -99,7 +99,7 @@ async function handler(ctx) { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const description = $('div > div > div > div > div > div > div:nth-child(4)'); item.description = description.length ? description.html() : item.description; diff --git a/lib/routes/hypergryph/endfield/news.ts b/lib/routes/hypergryph/endfield/news.ts index 504d5f10f..fdacda124 100644 --- a/lib/routes/hypergryph/endfield/news.ts +++ b/lib/routes/hypergryph/endfield/news.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { config } from '@/config'; import type { Route } from '@/types'; @@ -73,7 +73,7 @@ async function handler(ctx) { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); // The detail page's article HTML appears in one of two shapes // within the Next.js RSC stream (self.__next_f.push chunks): diff --git a/lib/routes/imdb/chart.tsx b/lib/routes/imdb/chart.tsx index b33d0e8f1..6485e8eee 100644 --- a/lib/routes/imdb/chart.tsx +++ b/lib/routes/imdb/chart.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import { renderToString } from 'hono/jsx/dom/server'; @@ -67,7 +67,7 @@ async function handler(ctx: Context) { const link = `${baseUrl}/chart/${chart}/`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); const chartTitles = nextData.props.pageProps.pageData.chartTitles as ChartTitleSearchConnection; diff --git a/lib/routes/juejin/utils.ts b/lib/routes/juejin/utils.ts index 6a33aaa87..0a28aeaca 100644 --- a/lib/routes/juejin/utils.ts +++ b/lib/routes/juejin/utils.ts @@ -1,6 +1,6 @@ import crypto from 'node:crypto'; -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import cache from '@/utils/cache'; import ofetch from '@/utils/ofetch'; @@ -44,7 +44,7 @@ export const generateUuid = () => { export const getArticle = async (link) => { let response = await ofetch(link); - let $ = cheerio.load(response); + let $ = load(response); if ($('script').text().includes('_wafchallengeid')) { const cs = $('script:contains("_wafchallengeid")') .text() @@ -57,7 +57,7 @@ export const getArticle = async (link) => { }, }); - $ = cheerio.load(response); + $ = load(response); } return $('.article-viewer').html(); diff --git a/lib/routes/kpmg/insights.tsx b/lib/routes/kpmg/insights.tsx index 4d97b9e54..6c91088be 100644 --- a/lib/routes/kpmg/insights.tsx +++ b/lib/routes/kpmg/insights.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -103,7 +103,7 @@ const handler = async (ctx: Context) => { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const content = $('.bodytext-data') .toArray() diff --git a/lib/routes/kurogames/wutheringwaves/news.ts b/lib/routes/kurogames/wutheringwaves/news.ts index 8727d7c0e..9c14d8b8a 100644 --- a/lib/routes/kurogames/wutheringwaves/news.ts +++ b/lib/routes/kurogames/wutheringwaves/news.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { DataItem, Route } from '@/types'; import cache from '@/utils/cache'; @@ -70,7 +70,7 @@ Language codes for the \`${Parameter.Language}\` parameter: // Article content may not always be available, e.g: https://wutheringwaves.kurogames.com/zh-tw/main/news/detail/2596 const articleContent = articleDetails.articleContent ?? ''; - const $ = cheerio.load(articleContent); + const $ = load(articleContent); item.description = $.html() ?? article.articleDesc ?? ''; diff --git a/lib/routes/lianxh/index.ts b/lib/routes/lianxh/index.ts index 9bcbd621c..b47b6b0ba 100644 --- a/lib/routes/lianxh/index.ts +++ b/lib/routes/lianxh/index.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import markdownit from 'markdown-it'; @@ -76,7 +76,7 @@ async function handler(ctx: Context) { const response = await ofetch(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.card-body > a') .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')!) : 30) diff --git a/lib/routes/luogu/user-article.ts b/lib/routes/luogu/user-article.ts index 733716ab7..1436a065d 100644 --- a/lib/routes/luogu/user-article.ts +++ b/lib/routes/luogu/user-article.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -59,7 +59,7 @@ async function handler(ctx) { posts.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('div#rendered-preview').html(); return item; diff --git a/lib/routes/matters/tags.ts b/lib/routes/matters/tags.ts index 1377780be..b3fb57364 100644 --- a/lib/routes/matters/tags.ts +++ b/lib/routes/matters/tags.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -16,7 +16,7 @@ interface Tag { const getTagId = (tid: string) => cache.tryGet(`matters:tags:${tid}`, async () => { const response = await ofetch(`${baseUrl}/tags/${tid}`); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); const node = Object.entries(nextData.props.apolloState.data.ROOT_QUERY) diff --git a/lib/routes/mingpao/index.tsx b/lib/routes/mingpao/index.tsx index b2273ea22..79ee66cfa 100644 --- a/lib/routes/mingpao/index.tsx +++ b/lib/routes/mingpao/index.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -124,7 +124,7 @@ async function handler(ctx) { }, }); - const $ = cheerio.load(response); + const $ = load(response); const topVideo = $('#topvideo').length ? $('#topvideo iframe') .toArray() @@ -155,7 +155,7 @@ async function handler(ctx) { ?.replaceAll(String.raw`\"`, '"') : ''; if (lowerContent) { - const $ = cheerio.load(lowerContent, null, false); + const $ = load(lowerContent, null, false); fancybox = [ ...fancybox, ...$('a.fancybox') diff --git a/lib/routes/missav/new.tsx b/lib/routes/missav/new.tsx index c1c17a61e..c45a12df3 100644 --- a/lib/routes/missav/new.tsx +++ b/lib/routes/missav/new.tsx @@ -1,5 +1,5 @@ // import ofetch from '@/utils/ofetch'; -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { renderToString } from 'hono/jsx/dom/server'; import type { Route } from '@/types'; @@ -57,7 +57,7 @@ async function handler() { // }, // }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.grid .group') .toArray() diff --git a/lib/routes/nmc/weatheralarm.ts b/lib/routes/nmc/weatheralarm.ts index 9cac7a1cd..152a0a4e5 100644 --- a/lib/routes/nmc/weatheralarm.ts +++ b/lib/routes/nmc/weatheralarm.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -53,7 +53,7 @@ async function handler(ctx) { list.map((item) => cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('#icon').html() + diff --git a/lib/routes/patreon/feed.tsx b/lib/routes/patreon/feed.tsx index d30021b9e..7d0d93d67 100644 --- a/lib/routes/patreon/feed.tsx +++ b/lib/routes/patreon/feed.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -118,7 +118,7 @@ async function handler(ctx) { const creatorData = (await cache.tryGet(`patreon:creator:${creator}`, async () => { const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const ogUrl = $('meta[property="og:url"]').attr('content'); if (ogUrl?.startsWith(`${baseUrl}/cw/`)) { diff --git a/lib/routes/psnine/game.ts b/lib/routes/psnine/game.ts index 8481ce6dc..e14b15194 100644 --- a/lib/routes/psnine/game.ts +++ b/lib/routes/psnine/game.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; @@ -7,7 +7,7 @@ const handler = async () => { const url = 'https://www.psnine.com/psngame'; const response = await ofetch(url); - const $ = cheerio.load(response); + const $ = load(response); const out = $('table tr') .toArray() diff --git a/lib/routes/psnine/index.ts b/lib/routes/psnine/index.ts index 8958f0145..093ac7170 100644 --- a/lib/routes/psnine/index.ts +++ b/lib/routes/psnine/index.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; @@ -8,7 +8,7 @@ const handler = async () => { const url = 'https://www.psnine.com/'; const response = await ofetch(url); - const $ = cheerio.load(response); + const $ = load(response); const out = $('.list li') .toArray() diff --git a/lib/routes/psnine/node.ts b/lib/routes/psnine/node.ts index bb6b51508..8a00d35df 100644 --- a/lib/routes/psnine/node.ts +++ b/lib/routes/psnine/node.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -13,7 +13,7 @@ const handler = async (ctx) => { const currentUrl = `${rootUrl}/node/${id}?ob=${order}`; const response = await ofetch(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); $('.psnnode, .node').remove(); @@ -44,7 +44,7 @@ const handler = async (ctx) => { list.map((item) => cache.tryGet(item.link, async () => { const detailResponse = await ofetch(item.link); - const $ = cheerio.load(detailResponse); + const $ = load(detailResponse); item.author = $('a[itemprop="author"]').eq(0).text(); item.description = $('div[itemprop="articleBody"]').html(); diff --git a/lib/routes/psnine/shuzhe.ts b/lib/routes/psnine/shuzhe.ts index 2cb7390b8..0e15530d7 100644 --- a/lib/routes/psnine/shuzhe.ts +++ b/lib/routes/psnine/shuzhe.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; @@ -7,7 +7,7 @@ const handler = async () => { const url = 'https://www.psnine.com/dd'; const response = await ofetch(url); - const $ = cheerio.load(response); + const $ = load(response); const out = $('.dd_ul li') .toArray() diff --git a/lib/routes/psnine/trade.ts b/lib/routes/psnine/trade.ts index d0af672d6..f3c4f7815 100644 --- a/lib/routes/psnine/trade.ts +++ b/lib/routes/psnine/trade.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; @@ -8,7 +8,7 @@ const handler = async () => { const url = 'https://www.psnine.com/trade'; const response = await ofetch(url); - const $ = cheerio.load(response); + const $ = load(response); const out = $('.list li') .toArray() diff --git a/lib/routes/qstheory/index.ts b/lib/routes/qstheory/index.ts index 6a56330c5..10fbfd1f3 100644 --- a/lib/routes/qstheory/index.ts +++ b/lib/routes/qstheory/index.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -98,7 +98,7 @@ async function handler(ctx) { const currentUrl = config[category].url; const response = await ofetch(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.list-style1 ul li a, .text h2 a, .no-pic ul li a') .slice(0, limit) diff --git a/lib/routes/qstheory/magazine.ts b/lib/routes/qstheory/magazine.ts index 532f90092..69e2f5bc4 100644 --- a/lib/routes/qstheory/magazine.ts +++ b/lib/routes/qstheory/magazine.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -27,7 +27,7 @@ async function handler(ctx) { const link = `${baseUrl}/${magazine}/mulu.htm`; const yearResponse = await ofetch(link); - const $ = cheerio.load(yearResponse); + const $ = load(yearResponse); const yearList = $('.booktitle a') .toArray() @@ -40,7 +40,7 @@ async function handler(ctx) { }); const issueResponse = await ofetch(yearList[0].link); - const $$ = cheerio.load(issueResponse); + const $$ = load(issueResponse); const list = $$('.highlight a') .toArray() diff --git a/lib/routes/qstheory/utils.ts b/lib/routes/qstheory/utils.ts index eda6b3c06..c87ad73d1 100644 --- a/lib/routes/qstheory/utils.ts +++ b/lib/routes/qstheory/utils.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; @@ -7,7 +7,7 @@ export const baseUrl = 'http://www.qstheory.cn'; export const getItem = async (item) => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.fs-text, .fs-pinglun, .hidden-xs').remove(); diff --git a/lib/routes/sega/maimaidx.ts b/lib/routes/sega/maimaidx.ts index 57c40c3a9..a452c1f8f 100644 --- a/lib/routes/sega/maimaidx.ts +++ b/lib/routes/sega/maimaidx.ts @@ -1,4 +1,6 @@ -import * as cheerio from 'cheerio'; +import type { Cheerio } from 'cheerio'; +import { load } from 'cheerio'; +import type { Element } from 'domhandler'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -23,8 +25,8 @@ export const route: Route = { async function handler() { const baseUrl = 'https://info-maimai.sega.jp/'; - const parseContent = (htmlString: string, image: cheerio.Cheerio) => { - const $ = cheerio.load(htmlString); + const parseContent = (htmlString: string, image: Cheerio) => { + const $ = load(htmlString); const content = $('.maiMd'); content.prepend(image); content.find('.hrLine').replaceWith('
'); @@ -32,7 +34,7 @@ async function handler() { }; const response = await got(baseUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.maiPager-content .newsBox'); const item = await Promise.all( diff --git a/lib/routes/sega/pjsekai.ts b/lib/routes/sega/pjsekai.ts index 85e3844c9..579a9f877 100644 --- a/lib/routes/sega/pjsekai.ts +++ b/lib/routes/sega/pjsekai.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -45,7 +45,7 @@ async function handler() { try { description = await cache.tryGet(guid, async () => { const result = await got.get(`https://production-web.sekai.colorfulpalette.org/html/${path}.html`); - const $ = cheerio.load(result.data); + const $ = load(result.data); return $.html(); }); } catch { diff --git a/lib/routes/sohu/mobile.ts b/lib/routes/sohu/mobile.ts index d043de6b5..9d4af0dff 100644 --- a/lib/routes/sohu/mobile.ts +++ b/lib/routes/sohu/mobile.ts @@ -1,4 +1,5 @@ -import * as cheerio from 'cheerio'; +import type { CheerioAPI } from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -34,7 +35,7 @@ export const route: Route = { async function handler() { const response = await ofetch('https://m.sohu.com/limit'); // 从HTML中提取JSON数据 - const $ = cheerio.load(response); + const $ = load(response); const jsonScript = $('script:contains("WapHomeRenderData")').text(); const jsonMatch = jsonScript?.match(/window\.WapHomeRenderData\s*=\s*(\{.*\})/s); if (!jsonMatch?.[1]) { @@ -52,14 +53,14 @@ async function handler() { cache.tryGet(item.link, async () => { try { const detailResp = await ofetch(item.link); - const $d = cheerio.load(detailResp); + const $d = load(detailResp); let description = ''; let pubDate = ''; if (item.link.includes('/xtopic/')) { const fullArticleUrl = $d('.tpl-top-text-item-content').prop('href')?.split('?', 1)[0]?.replace('www.sohu.com/', 'm.sohu.com/'); const response = await ofetch(`https:${fullArticleUrl}`); - const $ = cheerio.load(response); + const $ = load(response); description = getDescription($); pubDate = extractPubDate($); } @@ -108,7 +109,7 @@ function extractPlateBlockNewsLists(jsonData: any) { return result; } -function extractPubDate($: cheerio.CheerioAPI): string { +function extractPubDate($: CheerioAPI): string { const timeElements = ['.time', '#videoPublicTime']; let date; for (const selector of timeElements) { @@ -133,7 +134,7 @@ function extractPubDate($: cheerio.CheerioAPI): string { } } -function getDescription($: cheerio.CheerioAPI): string | null { +function getDescription($: CheerioAPI): string | null { const content = $('#articleContent'); if (content.length) { return content.first().html()?.trim(); diff --git a/lib/routes/sohu/mp.tsx b/lib/routes/sohu/mp.tsx index 2cc23572f..2b8a90ca6 100644 --- a/lib/routes/sohu/mp.tsx +++ b/lib/routes/sohu/mp.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import CryptoJS from 'crypto-js'; import { renderToString } from 'hono/jsx/dom/server'; @@ -57,7 +57,7 @@ function createAuthToken() { function fetchArticle(item) { return cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.original-title, .lookall-box').remove(); item.author ||= $('span[data-role="original-link"] a').text(); @@ -118,7 +118,7 @@ async function handler(ctx) { ?.getSetCookie() .find((e) => e.startsWith('SUV')) ?.split(';', 1)[0]; - const $ = cheerio.load(pageResponse._data); + const $ = load(pageResponse._data); const CBDRenderConst = JSON.parse( $('script:contains("CBDRenderConst")') diff --git a/lib/routes/spankbang/new-videos.tsx b/lib/routes/spankbang/new-videos.tsx index 65f0fab99..de6461088 100644 --- a/lib/routes/spankbang/new-videos.tsx +++ b/lib/routes/spankbang/new-videos.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import { renderToString } from 'hono/jsx/dom/server'; import { config } from '@/config'; @@ -38,7 +38,7 @@ const handler = async () => { }); const response = await page.content(); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.video-item') .toArray() diff --git a/lib/routes/t66y/index.ts b/lib/routes/t66y/index.ts index 9d78537c7..aa508c4b2 100644 --- a/lib/routes/t66y/index.ts +++ b/lib/routes/t66y/index.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -67,7 +67,7 @@ async function handler(ctx) { isValidType && url.searchParams.set('type', type); const { data: res } = await got(url); - const $ = cheerio.load(res); + const $ = load(res); const list = $('#ajaxtable > tbody:nth-child(2) .tr3') .not('.tr2.tac') .toArray() diff --git a/lib/routes/t66y/post.ts b/lib/routes/t66y/post.ts index 9d585d095..7c7416e2a 100644 --- a/lib/routes/t66y/post.ts +++ b/lib/routes/t66y/post.ts @@ -1,4 +1,5 @@ -import * as cheerio from 'cheerio'; +import type { CheerioAPI } from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -7,7 +8,7 @@ import { parseDate } from '@/utils/parse-date'; import { baseUrl, parseContent } from './utils'; -function parseItems(tid: string, $: cheerio.CheerioAPI) { +function parseItems(tid: string, $: CheerioAPI) { return $('.tr1:nth-child(1)') .toArray() .map((item) => { @@ -60,14 +61,14 @@ async function handler(ctx) { const tid = ctx.req.param('tid') as string; const { data: response } = await got(`${baseUrl}/read.php?tid=${tid}`); // 跟踪重定向 - let $ = cheerio.load(response); + let $ = load(response); const redirect = $('a:last-child').attr('href'); if (!redirect) { throw new Error('Cannot get the redirect link'); } const { data: redirectedResponse, url: link } = await got(new URL(redirect, baseUrl).href); - $ = cheerio.load(redirectedResponse); + $ = load(redirectedResponse); const firstPage = parseItems(tid, $); @@ -84,7 +85,7 @@ async function handler(ctx) { pageUrls.map((url) => cache.tryGet(url, async () => { const { data: res } = await got(url); - const $ = cheerio.load(res); + const $ = load(res); return parseItems(tid, $); }) diff --git a/lib/routes/t66y/utils.ts b/lib/routes/t66y/utils.ts index 36f7e825e..87f782bc3 100644 --- a/lib/routes/t66y/utils.ts +++ b/lib/routes/t66y/utils.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; export const baseUrl = 'https://www.t66y.com'; @@ -10,7 +10,7 @@ const killRedircdn = (originUrl) => { }; export const parseContent = (htmlString) => { - const $ = cheerio.load(htmlString); + const $ = load(htmlString); const content = $('div.tpc_content').eq(0); content.find('.t_like').remove(); diff --git a/lib/routes/telegram/blog.ts b/lib/routes/telegram/blog.ts index c8ee415f6..259501330 100644 --- a/lib/routes/telegram/blog.ts +++ b/lib/routes/telegram/blog.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import { ViewType } from '@/types'; @@ -35,7 +35,7 @@ async function handler() { const link = 'https://telegram.org/blog'; const res = await ofetch(link); - const $$ = cheerio.load(res); + const $$ = load(res); const items = await Promise.all( $$('.dev_blog_card_link_wrap') @@ -45,7 +45,7 @@ async function handler() { const link = 'https://telegram.org' + $.attr('href'); return cache.tryGet(link, async () => { const result = await ofetch(link); - const $ = cheerio.load(result); + const $ = load(result); return { title: $('#dev_page_title').text(), link, diff --git a/lib/routes/thepaper/user.ts b/lib/routes/thepaper/user.ts index ed019dd67..e4ed7db64 100644 --- a/lib/routes/thepaper/user.ts +++ b/lib/routes/thepaper/user.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -110,7 +110,7 @@ async function handler(ctx) { const mobileBuildId = (await cache.tryGet('thepaper:m:buildId', async () => { const response = await ofetch('https://m.thepaper.cn'); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); return nextData.buildId; })) as string; diff --git a/lib/routes/tongli/news.ts b/lib/routes/tongli/news.ts index 3ecc6a364..651c1ba75 100644 --- a/lib/routes/tongli/news.ts +++ b/lib/routes/tongli/news.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -33,7 +33,7 @@ async function handler(ctx) { Page: 1, }, }); - const $ = cheerio.load(res); + const $ = load(res); const list = $('.news_list ul li') .toArray() @@ -51,7 +51,7 @@ async function handler(ctx) { list.map((item) => cache.tryGet(item.link, async () => { const { data: res } = await got(item.link); - const $ = cheerio.load(res); + const $ = load(res); if (item.link.startsWith('https://tonglinv.pixnet.net/')) { item.description = $('.article-content-inner').html(); diff --git a/lib/routes/vertikal/latest.ts b/lib/routes/vertikal/latest.ts index 3374723f6..144528bba 100644 --- a/lib/routes/vertikal/latest.ts +++ b/lib/routes/vertikal/latest.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -29,7 +29,7 @@ async function handler() { page: 1, }, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.grid__column') .toArray() @@ -47,7 +47,7 @@ async function handler() { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const content = $('.newsentry'); diff --git a/lib/routes/wired/tag.ts b/lib/routes/wired/tag.ts index 60b4c5c44..73733cfe1 100644 --- a/lib/routes/wired/tag.ts +++ b/lib/routes/wired/tag.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -27,7 +27,7 @@ async function handler(ctx) { const link = `${baseUrl}/tag/${tag}/`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const preloadedState = JSON.parse( $('script:contains("window.__PRELOADED_STATE__")') .text() @@ -47,7 +47,7 @@ async function handler(ctx) { list.map((item) => cache.tryGet(item.link, async () => { const response = await ofetch(item.link); - const $ = cheerio.load(response); + const $ = load(response); const preloadedState = JSON.parse( $('script:contains("window.__PRELOADED_STATE__")') .text() @@ -57,7 +57,7 @@ async function handler(ctx) { const headerLeadAsset = $('div[data-testid*="ContentHeaderLeadAsset"]'); headerLeadAsset.find('button').remove(); // false postive: 'some' does not exist on type 'Cheerio' - // eslint-disable-next-line unicorn/prefer-array-some + // oxlint-disable-next-line unicorn/prefer-array-some if (headerLeadAsset.find('video')) { headerLeadAsset.find('video').attr('src', $('link[rel="preload"][as="video"]').attr('href')); headerLeadAsset.find('video').attr('controls', ''); diff --git a/lib/routes/yenpress/series.tsx b/lib/routes/yenpress/series.tsx index 2e53c3db1..4e67cb744 100644 --- a/lib/routes/yenpress/series.tsx +++ b/lib/routes/yenpress/series.tsx @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Context } from 'hono'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -32,7 +32,7 @@ async function handler(ctx: Context) { const link = `https://yenpress.com/series/${series}`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.show-more-container .inline_block') .toArray() @@ -48,7 +48,7 @@ async function handler(ctx: Context) { list.map((item) => cache.tryGet(item.link!, async () => { const response = await ofetch(item.link!); - const $ = cheerio.load(response); + const $ = load(response); item.category = $('.detail-labels.mobile-only') .eq(0) diff --git a/lib/routes/youtube/api/google.ts b/lib/routes/youtube/api/google.ts index 8c43d17a2..568f404c8 100644 --- a/lib/routes/youtube/api/google.ts +++ b/lib/routes/youtube/api/google.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration.js'; import { google } from 'googleapis'; @@ -65,7 +65,7 @@ export const getDataByUsername = async ({ username, embed, filterShorts, isJsonF userHandleData = await cache.tryGet(`youtube:handle:${username}`, async () => { const link = `https://www.youtube.com/${username}`; const response = await ofetch(link); - const $ = cheerio.load(response); + const $ = load(response); const ytInitialData = JSON.parse( $('script') .text() diff --git a/lib/routes/zaker/channel.ts b/lib/routes/zaker/channel.ts index 7416c493e..a3f74c24b 100644 --- a/lib/routes/zaker/channel.ts +++ b/lib/routes/zaker/channel.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import pMap from 'p-map'; import type { Route } from '@/types'; @@ -29,7 +29,7 @@ async function handler(ctx) { const { cookie, data } = await getSafeLineCookieWithData(link); - const $ = cheerio.load(data); + const $ = load(data); const feedTitle = $('head title').text(); const list = parseList($); diff --git a/lib/routes/zaker/focus.ts b/lib/routes/zaker/focus.ts index 3442eae46..38b905d1b 100644 --- a/lib/routes/zaker/focus.ts +++ b/lib/routes/zaker/focus.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import pMap from 'p-map'; import type { Route } from '@/types'; @@ -25,7 +25,7 @@ async function handler() { const { cookie, data } = await getSafeLineCookieWithData(link); - const $ = cheerio.load(data); + const $ = load(data); const list = parseList($); const items = await pMap(list, (item) => cache.tryGet(item.link!, () => fetchItem(item, cookie)), { concurrency: 2 }); diff --git a/lib/routes/zaker/utils.ts b/lib/routes/zaker/utils.ts index 262322d6b..56e197d8e 100644 --- a/lib/routes/zaker/utils.ts +++ b/lib/routes/zaker/utils.ts @@ -1,4 +1,5 @@ -import * as cheerio from 'cheerio'; +import type { CheerioAPI } from 'cheerio'; +import { load } from 'cheerio'; import CryptoJS from 'crypto-js'; import { config } from '@/config'; @@ -6,8 +7,7 @@ import type { DataItem } from '@/types'; import cache from '@/utils/cache'; import logger from '@/utils/logger'; import ofetch from '@/utils/ofetch'; -import { parseDate } from '@/utils/parse-date'; -import timezone from '@/utils/timezone'; +import { parseRelativeDate } from '@/utils/parse-date'; const hints = ['globalThis', 'headless', 'languages', 'permHook', 'vendor', 'webDriverValue', 'webdriver']; export const baseUrl = 'https://www.myzaker.com'; @@ -52,7 +52,13 @@ export const getSafeLineCookieWithData = async (link): Promise<{ cookie: string; const cacheAge = 3600; const cacheIn = await cache.get(cacheKey, false); if (cacheIn) { - return JSON.parse(cacheIn); + const cookie = JSON.parse(cacheIn); + const data = await ofetch(link, { + headers: { + Cookie: cookie, + }, + }); + return { cookie, data }; } const apiBaseUrl = 'https://challenge.rivers.chaitin.cn/captcha/api'; @@ -146,7 +152,7 @@ export const getSafeLineCookieWithData = async (link): Promise<{ cookie: string; }; }; -export const parseList = ($: cheerio.CheerioAPI) => { +export const parseList = ($: CheerioAPI) => { const winPageData = JSON.parse( $('script:contains("window.WinPageData")') .text() @@ -158,7 +164,7 @@ export const parseList = ($: cheerio.CheerioAPI) => { description: item.desc, link: 'https:' + item.url, author: item.author_name, - pubDate: timezone(parseDate(item.date, 'MM月DD日'), 8), + pubDate: parseRelativeDate(item.date, 'MM月DD日'), category: item.tag.map((t) => t.tag), image: item.thumbnail_mpic, })) as DataItem[]; @@ -171,7 +177,7 @@ export const fetchItem = async (item: DataItem, cookie: string) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const content = $('div.article_content div'); content.find('img').each((_, img) => { diff --git a/lib/routes/zhizhuan100/report.ts b/lib/routes/zhizhuan100/report.ts index 98d44ce7a..26ea826f6 100644 --- a/lib/routes/zhizhuan100/report.ts +++ b/lib/routes/zhizhuan100/report.ts @@ -1,4 +1,4 @@ -import * as cheerio from 'cheerio'; +import { load } from 'cheerio'; import type { Route } from '@/types'; import { ViewType } from '@/types'; @@ -23,7 +23,7 @@ export const route: Route = { async function handler() { const urlData = await ofetch('https://www.zhizhuan100.com.cn/analysis'); - const $ = cheerio.load(urlData); + const $ = load(urlData); const bodyJsUrl: string | undefined = $('script[src*="Body.js"]').attr('src'); @@ -41,7 +41,7 @@ async function handler() { } const htmlContent = JSON.parse(`"${htmlMatch[1]}"`); - const $content = cheerio.load(htmlContent); + const $content = load(htmlContent); const listItems = $content('.w-list-item');