From a98de2effd0a59fdf003fd0762fe3b9188ba8fe5 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 11 May 2026 02:16:04 +0800 Subject: [PATCH] refactor: use arrow function --- .oxlintrc.json | 16 ++++++++ lib/middleware/anti-hotlink.ts | 6 +-- lib/routes/163/exclusive.ts | 6 +-- lib/routes/163/news/rank.ts | 4 +- lib/routes/2048/index.tsx | 10 ++--- lib/routes/8264/list.tsx | 6 +-- lib/routes/abc/index.ts | 4 +- lib/routes/abskoop/index.ts | 4 +- lib/routes/android/platform-tools-releases.ts | 4 +- lib/routes/aqara/post.tsx | 6 +-- lib/routes/bad/index.ts | 20 +++++----- lib/routes/btzj/index.tsx | 10 ++--- lib/routes/bupt/jwc.ts | 4 +- lib/routes/bupt/scss.ts | 4 +- lib/routes/cbaigui/index.ts | 12 +++--- lib/routes/chinanews/index.ts | 4 +- lib/routes/coomer/index.tsx | 14 +++---- lib/routes/cyzone/util.ts | 8 ++-- lib/routes/darwinawards/index.ts | 4 +- lib/routes/disinfo/publications.ts | 4 +- lib/routes/diskanalyzer/whats-new.ts | 8 ++-- lib/routes/distill/index.ts | 4 +- lib/routes/dlsite/ci-en/article.ts | 4 +- lib/routes/eastday/24.ts | 4 +- lib/routes/ecust/jwc/notice.ts | 11 ++--- lib/routes/flyert/utils.ts | 6 +-- lib/routes/focustaiwan/index.tsx | 4 +- lib/routes/futunn/main.ts | 4 +- lib/routes/futunn/topic.ts | 4 +- lib/routes/gamersecret/index.ts | 4 +- lib/routes/gdut/oa-news.ts | 40 +++++++++---------- lib/routes/getdr/index.ts | 4 +- lib/routes/gxmzu/utils/index.ts | 4 +- lib/routes/hackernews/index.ts | 10 ++--- lib/routes/hitcon/zeroday.tsx | 4 +- lib/routes/hupu/all.tsx | 6 +-- lib/routes/hupu/utils.ts | 6 +-- lib/routes/imagemagick/changelog.ts | 4 +- lib/routes/javdb/utils.ts | 6 +-- lib/routes/javlibrary/utils.tsx | 6 +-- lib/routes/jou/utils/index.ts | 4 +- lib/routes/kamen-rider-official/news.ts | 10 ++--- lib/routes/kemono/index.tsx | 10 ++--- lib/routes/kisskiss/blog.ts | 6 +-- lib/routes/logonews/index.tsx | 6 +-- lib/routes/lorientlejour/index.tsx | 8 ++-- lib/routes/macfilos/blog.ts | 4 +- lib/routes/misskon/utils.ts | 4 +- lib/routes/neu/bmie.ts | 18 ++++----- lib/routes/newsmarket/index.ts | 6 +-- lib/routes/ngocn2/index.ts | 4 +- lib/routes/njxzc/lib.ts | 8 ++-- lib/routes/njxzc/utils/index.ts | 8 ++-- lib/routes/nwnu/routes/lib/embed-resource.ts | 4 +- lib/routes/nytimes/daily-briefing-chinese.tsx | 4 +- lib/routes/odaily/activity.ts | 6 +-- lib/routes/odaily/user.ts | 6 +-- lib/routes/onet/utils.ts | 4 +- lib/routes/oreno3d/get-sec-page-data.ts | 16 ++++---- lib/routes/qq88/index.ts | 4 +- lib/routes/researchgate/publications.ts | 4 +- lib/routes/right/forum.ts | 4 +- lib/routes/rsc/journal.tsx | 6 +-- lib/routes/ruancan/utils.ts | 10 ++--- lib/routes/saraba1st/digest.tsx | 16 ++++---- lib/routes/sensortower/blog.ts | 6 +-- lib/routes/shoppingdesign/posts.ts | 4 +- lib/routes/sinchew/index.tsx | 8 ++-- lib/routes/subhd/index.ts | 4 +- lib/routes/swissinfo/index.ts | 4 +- lib/routes/telegram/channel.ts | 8 ++-- lib/routes/thenewslens/index.ts | 6 +-- lib/routes/wechat/announce.ts | 4 +- lib/routes/wenku8/chapter.ts | 6 +-- lib/routes/whu/util.ts | 10 ++--- lib/routes/wsj/utils.tsx | 4 +- lib/routes/wzu/news.ts | 6 +-- lib/routes/xjtu/dean.ts | 4 +- lib/routes/xjtu/ee-jzxx.ts | 4 +- lib/routes/xmnn/epaper.ts | 4 +- lib/routes/xyu/notices.ts | 4 +- lib/routes/ycwb/index.tsx | 14 +++---- lib/routes/zcool/discover.ts | 4 +- 83 files changed, 290 insertions(+), 287 deletions(-) diff --git a/.oxlintrc.json b/.oxlintrc.json index e44803a23..2be2bfecf 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -360,6 +360,22 @@ { "selector": "CallExpression[callee.name=\"load\"] AwaitExpression > CallExpression", "message": "Do not use await in call expressions. Extract the result into a variable first." + }, + { + "selector": "Identifier[name=\"_ctx\"]", + "message": "Usage of `_ctx` is not allowed." + }, + { + "selector": "CallExpression[callee.property.name=\"each\"] > FunctionExpression", + "message": "Use an arrow function instead." + }, + { + "selector": "CallExpression[callee.property.name=\"filter\"] > FunctionExpression", + "message": "Use an arrow function instead." + }, + { + "selector": "CallExpression[callee.property.name=\"map\"] > FunctionExpression", + "message": "Use an arrow function instead." } ], diff --git a/lib/middleware/anti-hotlink.ts b/lib/middleware/anti-hotlink.ts index b06a32ef1..49a849570 100644 --- a/lib/middleware/anti-hotlink.ts +++ b/lib/middleware/anti-hotlink.ts @@ -59,13 +59,13 @@ const replaceUrl = (template?: string, url?: string) => { }; const replaceUrls = ($: CheerioAPI, selector: string, template: string, attribute = 'src') => { - $(selector).each(function () { - const oldSrc = $(this).attr(attribute); + $(selector).each((_, el) => { + const oldSrc = $(el).attr(attribute); if (oldSrc) { const url = parseUrl(oldSrc); if (url && url.protocol !== 'data:') { // Cheerio will do the right thing to prohibit XSS. - $(this).attr(attribute, interpolate(template, url)); + $(el).attr(attribute, interpolate(template, url)); } } }); diff --git a/lib/routes/163/exclusive.ts b/lib/routes/163/exclusive.ts index 43029a88b..ef265de1b 100644 --- a/lib/routes/163/exclusive.ts +++ b/lib/routes/163/exclusive.ts @@ -163,10 +163,10 @@ async function handler(ctx) { content('.m-linkCard').remove(); - content('.m-photo').each(function () { - content(this).html( + content('.m-photo').each((_, el) => { + content(el).html( renderExclusiveDescription({ - image: content(this).find('img').attr('data-src'), + image: content(el).find('img').attr('data-src'), }) ); }); diff --git a/lib/routes/163/news/rank.ts b/lib/routes/163/news/rank.ts index 3436f581b..d7643a8d3 100644 --- a/lib/routes/163/news/rank.ts +++ b/lib/routes/163/news/rank.ts @@ -167,8 +167,8 @@ async function handler(ctx) { const content = load(detailResponse.data); content('.bot_word, .js-open-app, .s-img').remove(); - content('video').each(function () { - content(this).attr('src', content(this).attr('data-src')); + content('video').each((_, el) => { + content(el).attr('src', content(el).attr('data-src')); }); content('.article-body .image-lazy').each((_, elem) => { elem.attribs.src = elem.attribs['data-src'] ?? elem.attribs.src; diff --git a/lib/routes/2048/index.tsx b/lib/routes/2048/index.tsx index 2685996c8..46c1e5356 100644 --- a/lib/routes/2048/index.tsx +++ b/lib/routes/2048/index.tsx @@ -133,13 +133,13 @@ async function handler(ctx) { content('.ads, .tips').remove(); - content('ignore_js_op').each(function () { - const img = content(this).find('img'); + content('ignore_js_op').each((_, el) => { + const img = content(el).find('img'); const originalSrc = img.attr('data-original'); const fallbackSrc = img.attr('src'); // 判断是否有 data-original 属性,若有则使用其值,否则使用 src 属性值 const imgSrc = originalSrc || fallbackSrc; - content(this).replaceWith(``); + content(el).replaceWith(``); }); item.author = content('.fl.black').first().text(); @@ -174,8 +174,8 @@ async function handler(ctx) { } } - content('.showhide img').each(function () { - readTpc.append(`
`); + content('.showhide img').each((_, el) => { + readTpc.append(`
`); }); item.description = readTpc.html(); diff --git a/lib/routes/8264/list.tsx b/lib/routes/8264/list.tsx index 1dc72d45f..adcae9585 100644 --- a/lib/routes/8264/list.tsx +++ b/lib/routes/8264/list.tsx @@ -129,11 +129,11 @@ async function handler(ctx) { const pubDate = content('span.pub-time').text() || content('span.fby span').first().prop('title') || content('span.fby').first().text().split('发表于').pop().trim(); - content('img').each(function () { - content(this).replaceWith( + content('img').each((_, el) => { + content(el).replaceWith( renderToString(
- {content(this).prop('alt')} + {content(el).prop('alt')}
) ); diff --git a/lib/routes/abc/index.ts b/lib/routes/abc/index.ts index bc66f7119..a4eea5198 100644 --- a/lib/routes/abc/index.ts +++ b/lib/routes/abc/index.ts @@ -105,8 +105,8 @@ async function handler(ctx) { content('#body *, div[data-component="FeatureMedia"]') .children() - .each(function () { - const element = content(this); + .each((_, el) => { + const element = content(el); if (element.prop('tagName').toLowerCase() === 'figure') { element.replaceWith( renderDescription({ diff --git a/lib/routes/abskoop/index.ts b/lib/routes/abskoop/index.ts index 7252758e9..67fb0b6ae 100644 --- a/lib/routes/abskoop/index.ts +++ b/lib/routes/abskoop/index.ts @@ -48,8 +48,8 @@ async function handler(ctx) { $detail('article.post-content').find('.lwptoc').remove(); $detail('article.post-content').find('#related_posts').remove(); $detail('article.post-content').find('.entry-copyright').remove(); - $detail('article.post-content img').each(function () { - $detail(this).replaceWith(``); + $detail('article.post-content img').each((_, el) => { + $detail(el).replaceWith(``); }); item.description = $detail('article.post-content').html(); return item; diff --git a/lib/routes/android/platform-tools-releases.ts b/lib/routes/android/platform-tools-releases.ts index b8a7ac579..974d49c3f 100644 --- a/lib/routes/android/platform-tools-releases.ts +++ b/lib/routes/android/platform-tools-releases.ts @@ -53,8 +53,8 @@ async function handler() { const title = item.attr('data-text'); let description = ''; - item.nextUntil('h4').each(function () { - description += $(this).html(); + item.nextUntil('h4').each((_, el) => { + description += $(el).html(); }); return { diff --git a/lib/routes/aqara/post.tsx b/lib/routes/aqara/post.tsx index 0906de8a1..4861ba652 100644 --- a/lib/routes/aqara/post.tsx +++ b/lib/routes/aqara/post.tsx @@ -52,13 +52,13 @@ async function handler(ctx) { // To handle lazy-loaded images. - content('figure').each(function () { - const image = content(this).find('img'); + content('figure').each((_, el) => { + const image = content(el).find('img'); const src = (image.prop('data-actualsrc') ?? image.prop('data-original') ?? image.prop('src')).replace(/(-\d+x\d+)/, ''); const width = image.prop('data-rawwidth') ?? image.prop('width'); const height = image.prop('data-rawheight') ?? image.prop('height'); - content(this).replaceWith( + content(el).replaceWith( renderToString(
diff --git a/lib/routes/bad/index.ts b/lib/routes/bad/index.ts index a821ead9b..74fcfe60b 100644 --- a/lib/routes/bad/index.ts +++ b/lib/routes/bad/index.ts @@ -33,18 +33,18 @@ async function handler(ctx) { const a = item.find('a.title'); - item.find('img').each(function () { - $(this).attr('src', $(this).attr('data-echo')); - $(this).removeClass('lazy'); - $(this).removeAttr('data-echo'); - $(this).removeAttr('id'); + item.find('img').each((_, el) => { + $(el).attr('src', $(el).attr('data-echo')); + $(el).removeClass('lazy'); + $(el).removeAttr('data-echo'); + $(el).removeAttr('id'); }); - item.find('video').each(function () { - $(this).attr('poster', $(this).attr('data-echo')); - $(this).removeAttr('data-echo'); - $(this).removeAttr('onerror'); - $(this).removeAttr('id'); + item.find('video').each((_, el) => { + $(el).attr('poster', $(el).attr('data-echo')); + $(el).removeAttr('data-echo'); + $(el).removeAttr('onerror'); + $(el).removeAttr('id'); }); return { diff --git a/lib/routes/btzj/index.tsx b/lib/routes/btzj/index.tsx index 4b5d450af..ef9fb00d0 100644 --- a/lib/routes/btzj/index.tsx +++ b/lib/routes/btzj/index.tsx @@ -129,13 +129,13 @@ async function handler(ctx) { content('.attachlist') .find('a') - .each(function () { - content(this) + .each((_, el) => { + content(el) .children('img') - .attr('src', `${rootUrl}${content(this).children('img').attr('src')}`); - content(this).attr( + .attr('src', `${rootUrl}${content(el).children('img').attr('src')}`); + content(el).attr( 'href', - `${rootUrl}/${content(this) + `${rootUrl}/${content(el) .attr('href') .replace(/^attach-dialog/, 'attach-download')}` ); diff --git a/lib/routes/bupt/jwc.ts b/lib/routes/bupt/jwc.ts index f1c9507eb..9439c979e 100644 --- a/lib/routes/bupt/jwc.ts +++ b/lib/routes/bupt/jwc.ts @@ -98,8 +98,8 @@ async function handler(ctx: Context) { const newsContent = content('.v_news_content'); // 移除不必要的标签,比如

中无用的内容 - newsContent.find('p, span, strong').each(function () { - const element = content(this); + newsContent.find('p, span, strong').each((_, el) => { + const element = content(el); const text = element.text().trim(); // 删除没有有用文本的元素,防止空元素被保留 diff --git a/lib/routes/bupt/scss.ts b/lib/routes/bupt/scss.ts index 3a87e867e..7db560446 100644 --- a/lib/routes/bupt/scss.ts +++ b/lib/routes/bupt/scss.ts @@ -73,8 +73,8 @@ async function handler() { const content = load(detailResponse.data); const newsContent = content('.v_news_content'); - newsContent.find('p, span, strong').each(function () { - const element = content(this); + newsContent.find('p, span, strong').each((_, el) => { + const element = content(el); const text = element.text().trim(); if (text === '') { element.remove(); diff --git a/lib/routes/cbaigui/index.ts b/lib/routes/cbaigui/index.ts index b440f86a2..9a3872640 100644 --- a/lib/routes/cbaigui/index.ts +++ b/lib/routes/cbaigui/index.ts @@ -44,13 +44,13 @@ async function handler(ctx) { // To handle lazy-loaded images from external sites. - content('figure').each(function () { - const image = content(this).find('img'); + content('figure').each((_, el) => { + const image = content(el).find('img'); const src = image.prop('data-actualsrc') ?? image.prop('data-original'); const width = image.prop('data-rawwidth'); const height = image.prop('data-rawheight'); - content(this).replaceWith( + content(el).replaceWith( renderFigure({ src, width, @@ -61,13 +61,13 @@ async function handler(ctx) { // To remove watermarks on images. - content('p img').each(function () { - const image = content(this); + content('p img').each((_, el) => { + const image = content(el); const src = image.prop('src').split('!')[0]; const width = image.prop('width'); const height = image.prop('height'); - content(this).replaceWith( + content(el).replaceWith( renderFigure({ src, width, diff --git a/lib/routes/chinanews/index.ts b/lib/routes/chinanews/index.ts index aaccff0ba..f8b1a3b83 100644 --- a/lib/routes/chinanews/index.ts +++ b/lib/routes/chinanews/index.ts @@ -61,9 +61,7 @@ async function handler(ctx) { item.description = content('div.left_zw').html(); const info = content('div.left-t') .contents() - .filter(function () { - return this.type === 'text'; - }) + .filter((_, el) => el.type === 'text') .text() .split(' '); item.pubDate = timezone(parseDate(info[0], 'YYYY年MM月DD日 HH:mm'), +8); diff --git a/lib/routes/coomer/index.tsx b/lib/routes/coomer/index.tsx index 4afffa1b4..cdd0cd8d4 100644 --- a/lib/routes/coomer/index.tsx +++ b/lib/routes/coomer/index.tsx @@ -87,9 +87,7 @@ async function handler(ctx) { } const filesHTML = renderSource(i); let $ = load(filesHTML); - const coomerFiles = $('img, a, audio, video').map(function () { - return $(this).prop('outerHTML')!; - }); + const coomerFiles = $('img, a, audio, video').map((_, el) => $(el).prop('outerHTML')!); let desc = ''; if (i.content) { desc += `

${i.content}
`; @@ -97,11 +95,11 @@ async function handler(ctx) { $ = load(desc); let count = 0; const regex = /downloads.fanbox.cc/; - $('a').each(function () { - const link = $(this).attr('href'); + $('a').each((_, el) => { + const link = $(el).attr('href'); if (regex.test(link!)) { count++; - $(this).replaceWith(coomerFiles[count]); + $(el).replaceWith(coomerFiles[count]); } }); desc = (coomerFiles.length > 0 ? coomerFiles[0] : '') + $.html(); @@ -110,8 +108,8 @@ async function handler(ctx) { } let enclosureInfo = {}; - load(desc)('audio source, video source').each(function () { - const src = $(this).attr('src') ?? ''; + load(desc)('audio source, video source').each((_, el) => { + const src = $(el).attr('src') ?? ''; const mimeType = { m4a: 'audio/mp4', diff --git a/lib/routes/cyzone/util.ts b/lib/routes/cyzone/util.ts index 95f4b83b2..2f61635d0 100644 --- a/lib/routes/cyzone/util.ts +++ b/lib/routes/cyzone/util.ts @@ -89,11 +89,11 @@ const processItems = async (apiUrl, limit, tryGet, ...params) => { const content = load(data.content); - content('img').each(function () { - if (content(this).prop('src')) { - content(this).prop('src', content(this).prop('src').split('?')[0]); + content('img').each((_, el) => { + if (content(el).prop('src')) { + content(el).prop('src', content(el).prop('src').split('?')[0]); } else { - content(this).remove(); + content(el).remove(); } }); diff --git a/lib/routes/darwinawards/index.ts b/lib/routes/darwinawards/index.ts index 5b737ddfb..be8c7751e 100644 --- a/lib/routes/darwinawards/index.ts +++ b/lib/routes/darwinawards/index.ts @@ -31,8 +31,8 @@ async function handler() { $('.cameo').remove(); - $('.topvote_title_desc, .topvote_title_minimal, .topvote_minimal').each(function () { - $(this).find('a').first().remove(); + $('.topvote_title_desc, .topvote_title_minimal, .topvote_minimal').each((_, el) => { + $(el).find('a').first().remove(); }); let items = $('#article_index a') diff --git a/lib/routes/disinfo/publications.ts b/lib/routes/disinfo/publications.ts index 446807790..8d456fa99 100644 --- a/lib/routes/disinfo/publications.ts +++ b/lib/routes/disinfo/publications.ts @@ -63,8 +63,8 @@ async function handler() { content('.wp-block-spacer').remove(); content('.elementor-widget-container p').eq(0).remove(); - content('img').each(function () { - content(this).attr('src', content(this).attr('data-lazy-src')); + content('img').each((_, el) => { + content(el).attr('src', content(el).attr('data-lazy-src')); }); item.description = content('.elementor-widget-theme-post-content').html(); diff --git a/lib/routes/diskanalyzer/whats-new.ts b/lib/routes/diskanalyzer/whats-new.ts index ebdb7bece..d7457c5ed 100644 --- a/lib/routes/diskanalyzer/whats-new.ts +++ b/lib/routes/diskanalyzer/whats-new.ts @@ -47,14 +47,14 @@ async function handler() { const title = item.text(); let description = ''; - item.nextUntil('h4').each(function () { - description += $(this).html(); + item.nextUntil('h4').each((_, el) => { + description += $(el).html(); }); if (description === '') { item.parent() .nextUntil('h4') - .each(function () { - description += $(this).html(); + .each((_, el) => { + description += $(el).html(); }); } diff --git a/lib/routes/distill/index.ts b/lib/routes/distill/index.ts index 96a02766f..022f54bbf 100644 --- a/lib/routes/distill/index.ts +++ b/lib/routes/distill/index.ts @@ -52,8 +52,8 @@ async function handler() { content('d-contents').remove(); - content('img').each(function () { - content(this).attr('src', `${item.link}/${content(this).attr('src')}`); + content('img').each((_, el) => { + content(el).attr('src', `${item.link}/${content(el).attr('src')}`); }); item.doi = content('meta[name="citation_doi"]').attr('content'); diff --git a/lib/routes/dlsite/ci-en/article.ts b/lib/routes/dlsite/ci-en/article.ts index 7d01d9616..b05eb3dc6 100644 --- a/lib/routes/dlsite/ci-en/article.ts +++ b/lib/routes/dlsite/ci-en/article.ts @@ -70,8 +70,8 @@ async function handler(ctx) { content('.article-title').remove(); - content('.file-player-image').each(function () { - content(this).replaceWith(``); + content('.file-player-image').each((_, el) => { + content(el).replaceWith(``); }); item.description = content('article').html(); diff --git a/lib/routes/eastday/24.ts b/lib/routes/eastday/24.ts index 6c50ffdab..43ed7a699 100644 --- a/lib/routes/eastday/24.ts +++ b/lib/routes/eastday/24.ts @@ -103,8 +103,8 @@ async function handler(ctx) { }); const subContent = load(pageResponse.data); - subContent('img').each(function () { - subContent(this).attr('src', subContent(this).attr('data-url')); + subContent('img').each((_, el) => { + subContent(el).attr('src', subContent(el).attr('data-url')); }); item.description += subContent('#J-contain_detail_cnt').html(); diff --git a/lib/routes/ecust/jwc/notice.ts b/lib/routes/ecust/jwc/notice.ts index 8aecda512..056a09284 100644 --- a/lib/routes/ecust/jwc/notice.ts +++ b/lib/routes/ecust/jwc/notice.ts @@ -67,12 +67,13 @@ async function handler(ctx) { const { data: response } = await got(item.link); const content = load(response); // remove all attrs and empty objects - content('div.wp_articlecontent *').each(function () { - if (!content(this).text().trim()) { - return content(this).remove(); + content('div.wp_articlecontent *').each((_, el) => { + if (!content(el).text().trim()) { + content(el).remove(); + return; } - for (const attr in this.attribs) { - content(this).removeAttr(attr); + for (const attr in el.attribs) { + content(el).removeAttr(attr); } }); const description = content('div.wp_articlecontent').first().html(); diff --git a/lib/routes/flyert/utils.ts b/lib/routes/flyert/utils.ts index 78874f26b..5dbb268c5 100644 --- a/lib/routes/flyert/utils.ts +++ b/lib/routes/flyert/utils.ts @@ -26,11 +26,11 @@ async function loadContent(link) { const firstpost = $('.firstpost'); // 修改图片中的链接 - firstpost.find('ignore_js_op img').each(function () { - $(this).attr('src', $(this).attr('file')); + firstpost.find('ignore_js_op img').each((_, el) => { + $(el).attr('src', $(el).attr('file')); // 移除无用属性 for (const attr of ['id', 'aid', 'zoomfile', 'file', 'zoomfile', 'class', 'onclick', 'title', 'inpost', 'alt', 'onmouseover']) { - $(this).removeAttr(attr); + $(el).removeAttr(attr); } }); diff --git a/lib/routes/focustaiwan/index.tsx b/lib/routes/focustaiwan/index.tsx index da8b52e5a..3c10cd06e 100644 --- a/lib/routes/focustaiwan/index.tsx +++ b/lib/routes/focustaiwan/index.tsx @@ -67,8 +67,8 @@ async function handler(ctx) { const content = load(detailResponse.data); - content('img').each(function () { - content(this).html(``); + content('img').each((_, el) => { + content(el).html(``); }); const image = content('meta[property="og:image"]').attr('content'); diff --git a/lib/routes/futunn/main.ts b/lib/routes/futunn/main.ts index 92e3ddc0f..7ae650257 100644 --- a/lib/routes/futunn/main.ts +++ b/lib/routes/futunn/main.ts @@ -60,8 +60,8 @@ async function handler(ctx) { const content = load(detailResponse.data); content('.futu-news-time-stamp').remove(); - content('.nnstock').each(function () { - content(this).replaceWith(`${content(this).text().replaceAll('$', '')}`); + content('.nnstock').each((_, el) => { + content(el).replaceWith(`${content(el).text().replaceAll('$', '')}`); }); item.description = content('.origin_content').html(); diff --git a/lib/routes/futunn/topic.ts b/lib/routes/futunn/topic.ts index 6451c34a5..3430771d6 100644 --- a/lib/routes/futunn/topic.ts +++ b/lib/routes/futunn/topic.ts @@ -86,8 +86,8 @@ async function handler(ctx) { const content = load(detailResponse.data); content('.futu-news-time-stamp').remove(); - content('.nnstock').each(function () { - content(this).replaceWith(`${content(this).text().replaceAll('$', '')}`); + content('.nnstock').each((_, el) => { + content(el).replaceWith(`${content(el).text().replaceAll('$', '')}`); }); item.description = content('.origin_content').html(); diff --git a/lib/routes/gamersecret/index.ts b/lib/routes/gamersecret/index.ts index 6e6cbab45..4f91c1a47 100644 --- a/lib/routes/gamersecret/index.ts +++ b/lib/routes/gamersecret/index.ts @@ -86,8 +86,8 @@ async function handler(ctx) { const content = load(detailResponse.data); - content('img').each(function () { - content(this).attr('src', content(this).attr('data-src')); + content('img').each((_, el) => { + content(el).attr('src', content(el).attr('data-src')); }); item.author = content('.jeg_meta_author').text().replace(/by/, ''); diff --git a/lib/routes/gdut/oa-news.ts b/lib/routes/gdut/oa-news.ts index a190200fa..7b1159869 100644 --- a/lib/routes/gdut/oa-news.ts +++ b/lib/routes/gdut/oa-news.ts @@ -131,19 +131,15 @@ async function handler(ctx) { const node = $('#content'); // 清理样式 node.find('*') - .filter(function () { - return this.type === 'comment' || this.tagName === 'meta' || this.tagName === 'style'; - }) + .filter((_, el) => el.type === 'comment' || el.tagName === 'meta' || el.tagName === 'style') .remove(); node.find('*') .contents() - .filter(function () { - return this.type === 'comment' || this.tagName === 'meta' || this.tagName === 'style'; - }) + .filter((_, el) => el.type === 'comment' || el.tagName === 'meta' || el.tagName === 'style') .remove(); - node.find('*').each(function () { - if (this.attribs.style !== undefined) { - const newSty = this.attribs.style + node.find('*').each((_, el) => { + if (el.attribs.style !== undefined) { + const newSty = el.attribs.style .split(';') .filter((s) => { const styBlocklist = ['color:rgb(0,0,0)', 'color:black', 'background:rgb(255,255,255)', 'background:white', 'text-align:left', 'text-align:justify', 'font-style:normal', 'font-weight:normal']; @@ -176,27 +172,27 @@ async function handler(ctx) { }) .join(';'); if (newSty) { - this.attribs.style = newSty; + el.attribs.style = newSty; } else { - delete this.attribs.style; + delete el.attribs.style; } } - if (this.attribs.class && this.attribs.class.trim().startsWith('Mso')) { - delete this.attribs.class; + if (el.attribs.class && el.attribs.class.trim().startsWith('Mso')) { + delete el.attribs.class; } - if (this.attribs.lang) { - delete this.attribs.lang; + if (el.attribs.lang) { + delete el.attribs.lang; } - if (this.tagName === 'font' || this.tagName === 'o:p') { - $(this).replaceWith(this.childNodes); + if (el.tagName === 'font' || el.tagName === 'o:p') { + $(el).replaceWith(el.childNodes); } - if (this.tagName === 'span' && !this.attribs.style) { - $(this).replaceWith(this.childNodes); + if (el.tagName === 'span' && !el.attribs.style) { + $(el).replaceWith(el.childNodes); } }); - node.find('span').each(function () { - if (this.childNodes.length === 0) { - $(this).remove(); + node.find('span').each((_, el) => { + if (el.childNodes.length === 0) { + $(el).remove(); } }); diff --git a/lib/routes/getdr/index.ts b/lib/routes/getdr/index.ts index 03e9c631a..296d65b62 100644 --- a/lib/routes/getdr/index.ts +++ b/lib/routes/getdr/index.ts @@ -45,8 +45,8 @@ async function handler() { const content = load(detailResponse.data); - content('.wp-block-image').each(function () { - content(this).html(``); + content('.wp-block-image').each((_, el) => { + content(el).html(``); }); item.description = content('div[data-widget_type="theme-post-content.default"]').html(); diff --git a/lib/routes/gxmzu/utils/index.ts b/lib/routes/gxmzu/utils/index.ts index a12ee8949..44045ae3a 100644 --- a/lib/routes/gxmzu/utils/index.ts +++ b/lib/routes/gxmzu/utils/index.ts @@ -46,8 +46,8 @@ async function getNoticeList(ctx, url, host, titleSelector, dateSelector, conten item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { const $content = load($(contentSelector.content).html()); - $content('a').each(function () { - const a = $(this); + $content('a').each((_, el) => { + const a = $(el); const href = a.attr('href'); if (href && !href.startsWith('http')) { a.attr('href', new URL(href, host).href); diff --git a/lib/routes/hackernews/index.ts b/lib/routes/hackernews/index.ts index dff606d2c..a2b9b2b71 100644 --- a/lib/routes/hackernews/index.ts +++ b/lib/routes/hackernews/index.ts @@ -105,14 +105,14 @@ async function handler(ctx) { item.description = ''; - content('.comtr').each(function () { - const author = content(this).find('.hnuser'); - const comment = content(this).find('.commtext'); + content('.comtr').each((_, el) => { + const author = content(el).find('.hnuser'); + const comment = content(el).find('.commtext'); item.description += `
${author.text()}` + - `  ` + - `${content(this).find('.age').attr('title')}
`; + `  ` + + `${content(el).find('.age').attr('title')}
`; const commentText = comment.clone(); diff --git a/lib/routes/hitcon/zeroday.tsx b/lib/routes/hitcon/zeroday.tsx index aacc60097..f6c579a0a 100644 --- a/lib/routes/hitcon/zeroday.tsx +++ b/lib/routes/hitcon/zeroday.tsx @@ -71,9 +71,7 @@ async function handler(ctx: Context): Promise { const code = vulData .find('.code') .contents() - .filter(function () { - return this.nodeType === 3; - }) + .filter((_, el) => el.nodeType === 3) .text(); const risk = vulData.find('.risk span').eq(1).text(); const vender = vulData.find('.vender').find('.v-name-full').text(); diff --git a/lib/routes/hupu/all.tsx b/lib/routes/hupu/all.tsx index fc699861c..6514747f1 100644 --- a/lib/routes/hupu/all.tsx +++ b/lib/routes/hupu/all.tsx @@ -73,10 +73,10 @@ async function handler(ctx) { const videos = []; - content('.hupu-post-video').each(function () { + content('.hupu-post-video').each((_, el) => { videos.push({ - source: content(this).attr('src'), - poster: content(this).attr('poster'), + source: content(el).attr('src'), + poster: content(el).attr('poster'), }); }); diff --git a/lib/routes/hupu/utils.ts b/lib/routes/hupu/utils.ts index 726b0cfe5..2e6dba710 100644 --- a/lib/routes/hupu/utils.ts +++ b/lib/routes/hupu/utils.ts @@ -257,9 +257,9 @@ export function getEntryDetails(item: DataItem): Promise { .filter(Boolean); content('.basketballTobbs_tag').remove(); - content('.hupu-img').each(function () { - const imgSrc = content(this).attr('data-gif') || content(this).attr('data-origin') || content(this).attr('src'); - content(this).parent().html(``); + content('.hupu-img').each((_, el) => { + const imgSrc = content(el).attr('data-gif') || content(el).attr('data-origin') || content(el).attr('src'); + content(el).parent().html(``); }); // 分别获取内容元素 diff --git a/lib/routes/imagemagick/changelog.ts b/lib/routes/imagemagick/changelog.ts index b02047493..1f8b3da89 100644 --- a/lib/routes/imagemagick/changelog.ts +++ b/lib/routes/imagemagick/changelog.ts @@ -54,8 +54,8 @@ async function handler() { const title = item.text(); let description = ''; - item.nextUntil('h2').each(function () { - description += $(this).html(); + item.nextUntil('h2').each((_, el) => { + description += $(el).html(); }); return { diff --git a/lib/routes/javdb/utils.ts b/lib/routes/javdb/utils.ts index be78a271e..eaccdbef7 100644 --- a/lib/routes/javdb/utils.ts +++ b/lib/routes/javdb/utils.ts @@ -76,9 +76,9 @@ const ProcessItems = async (ctx, currentUrl, title) => { content('#modal-review-watched, #modal-comment-warning, #modal-save-list').remove(); content('.review-buttons, .copy-to-clipboard, .preview-video-container, .play-button').remove(); - content('.preview-images img').each(function () { - content(this).removeAttr('data-src'); - content(this).attr('src', content(this).parent().attr('href')); + content('.preview-images img').each((_, el) => { + content(el).removeAttr('data-src'); + content(el).attr('src', content(el).parent().attr('href')); }); item.category = content('.panel-block .value a') diff --git a/lib/routes/javlibrary/utils.tsx b/lib/routes/javlibrary/utils.tsx index e95f7ade6..6b0b10ff9 100644 --- a/lib/routes/javlibrary/utils.tsx +++ b/lib/routes/javlibrary/utils.tsx @@ -73,9 +73,9 @@ const ProcessItems = async (language, currentUrl, tryGet) => { const content = load(detailResponse.data); content('.icn_edit, .btn_videoplayer, a[rel="bookmark"]').remove(); - content('span').each(function () { - if (content(this).attr('class')?.startsWith('icn_')) { - content(this).remove(); + content('span').each((_, el) => { + if (content(el).attr('class')?.startsWith('icn_')) { + content(el).remove(); } }); diff --git a/lib/routes/jou/utils/index.ts b/lib/routes/jou/utils/index.ts index 6e1a09759..0389671e7 100644 --- a/lib/routes/jou/utils/index.ts +++ b/lib/routes/jou/utils/index.ts @@ -48,8 +48,8 @@ async function getItems(ctx, url, host, tableClass, timeStyleClass1, titleStyleC } else { const contentHtml = $('.v_news_content').html(); const $content = load(contentHtml); - $content('a').each(function () { - const a = $(this); + $content('a').each((_, el) => { + const a = $(el); const href = a.attr('href'); if (href && !href.startsWith('http')) { a.attr('href', new URL(href, host).href); diff --git a/lib/routes/kamen-rider-official/news.ts b/lib/routes/kamen-rider-official/news.ts index 20ea40e73..79a7f7201 100644 --- a/lib/routes/kamen-rider-official/news.ts +++ b/lib/routes/kamen-rider-official/news.ts @@ -107,14 +107,14 @@ async function handler(ctx) { const content = load(detailResponse); - content('a.c-button').each(function () { - content(this).parent().remove(); + content('a.c-button').each((_, el) => { + content(el).parent().remove(); }); - content('img').each(function () { - content(this).replaceWith( + content('img').each((_, el) => { + content(el).replaceWith( renderDescription({ - src: content(this).prop('src'), + src: content(el).prop('src'), }) ); }); diff --git a/lib/routes/kemono/index.tsx b/lib/routes/kemono/index.tsx index 454e5d47a..8392e394f 100644 --- a/lib/routes/kemono/index.tsx +++ b/lib/routes/kemono/index.tsx @@ -170,8 +170,8 @@ function generateEnclosureInfo(htmlContent: string): { enclosure_url?: string; e const $ = load(htmlContent); let enclosureInfo = {}; - $('audio source, video source').each(function () { - const src = $(this).attr('src'); + $('audio source, video source').each((_, el) => { + const src = $(el).attr('src'); if (!src) { return; } @@ -345,10 +345,10 @@ function processPosts(posts: KemonoPost[], authorName: string, limit: number) { let replacementCount = 0; const fanboxRegex = /downloads\.fanbox\.cc/; - $('a').each(function () { - const link = $(this).attr('href'); + $('a').each((_, el) => { + const link = $(el).attr('href'); if (link && fanboxRegex.test(link)) { - $(this).replaceWith(kemonoFileElements[replacementCount] || ''); + $(el).replaceWith(kemonoFileElements[replacementCount] || ''); replacementCount++; } }); diff --git a/lib/routes/kisskiss/blog.ts b/lib/routes/kisskiss/blog.ts index 83891a695..30cb72acc 100644 --- a/lib/routes/kisskiss/blog.ts +++ b/lib/routes/kisskiss/blog.ts @@ -58,9 +58,9 @@ async function handler(ctx) { 9 ), }; - body.find('a img').each(function () { - $(this).attr('src', $(this).parent('a').attr('href')); - $(this).unwrap(); + body.find('a img').each((_, el) => { + $(el).attr('src', $(el).parent('a').attr('href')); + $(el).unwrap(); }); body.find('div.blog_data').remove(); i.description = `
${body.html()}
`; diff --git a/lib/routes/logonews/index.tsx b/lib/routes/logonews/index.tsx index 552e9ac56..5e228c0d3 100644 --- a/lib/routes/logonews/index.tsx +++ b/lib/routes/logonews/index.tsx @@ -59,10 +59,10 @@ async function handler(ctx) { content('.iconfont').remove(); - content('img[data-src]').each(function () { - content(this).attr( + content('img[data-src]').each((_, el) => { + content(el).attr( 'src', - content(this) + content(el) .attr('data-src') .replace(/_logonews/, '') ); diff --git a/lib/routes/lorientlejour/index.tsx b/lib/routes/lorientlejour/index.tsx index e8d5cc77b..0d54c8adf 100644 --- a/lib/routes/lorientlejour/index.tsx +++ b/lib/routes/lorientlejour/index.tsx @@ -158,12 +158,12 @@ async function handler(ctx) { article.find('.inline-embeded-article').remove(); article.find('.relatedArticles').remove(); if (item.inline_attachments) { - article.find('.inlineImage').each(function () { - const inlineImageSrc = $(this).attr('src'); + article.find('.inlineImage').each((_, el) => { + const inlineImageSrc = $(el).attr('src'); const inlineAttachment = item.inline_attachments.find((inlineAttachment) => inlineAttachment.url === inlineImageSrc); if (inlineAttachment && inlineAttachment.description) { - $(this).wrap('
'); - $(this).after(`
${inlineAttachment.description}
`); + $(el).wrap('
'); + $(el).after(`
${inlineAttachment.description}
`); } }); } diff --git a/lib/routes/macfilos/blog.ts b/lib/routes/macfilos/blog.ts index 524bb2dc7..aac2c5478 100644 --- a/lib/routes/macfilos/blog.ts +++ b/lib/routes/macfilos/blog.ts @@ -69,8 +69,8 @@ async function handler(ctx) { content('hr').nextAll().remove(); content('hr').remove(); - content('img').each(function () { - content(this).removeAttr('srcset'); + content('img').each((_, el) => { + content(el).removeAttr('srcset'); }); item.description = content('.td-post-content').html(); diff --git a/lib/routes/misskon/utils.ts b/lib/routes/misskon/utils.ts index ad01798d4..c45554a41 100644 --- a/lib/routes/misskon/utils.ts +++ b/lib/routes/misskon/utils.ts @@ -11,8 +11,8 @@ const getPosts = async (searchParams) => { const data = await ofetch(url.href); return data.map((item) => { const $ = load(item.content.rendered); - $('input').each(function () { - $(this).replaceWith($(this).attr('value') || ''); + $('input').each((_, el) => { + $(el).replaceWith($(el).attr('value') || ''); }); $('script').remove(); return { diff --git a/lib/routes/neu/bmie.ts b/lib/routes/neu/bmie.ts index eb11a3d5f..46c70ce0e 100644 --- a/lib/routes/neu/bmie.ts +++ b/lib/routes/neu/bmie.ts @@ -91,22 +91,22 @@ async function handler(ctx) { const auhor = info.slice(au_start, au_end).trim(); $('.entry') .find('span') - .each(function () { - const temp = $(this).text(); - $(this).replaceWith(temp); + .each((_, el) => { + const temp = $(el).text(); + $(el).replaceWith(temp); }); $('.entry') .find('div') - .each(function () { - const temp = $(this).html(); - $(this).replaceWith(temp); + .each((_, el) => { + const temp = $(el).html(); + $(el).replaceWith(temp); }); $('.entry').find('a').remove(); $('.entry') .find('p') - .each(function () { - $(this).removeAttr('style'); - $(this).removeAttr('class'); + .each((_, el) => { + $(el).removeAttr('style'); + $(el).removeAttr('class'); }); $('.wp_art_adjoin').remove(); return { description: $('.entry').html(), date, author: auhor }; diff --git a/lib/routes/newsmarket/index.ts b/lib/routes/newsmarket/index.ts index 835502b06..2123f009d 100644 --- a/lib/routes/newsmarket/index.ts +++ b/lib/routes/newsmarket/index.ts @@ -71,10 +71,10 @@ async function handler(ctx) { const content = load(detailResponse.data); - content('figure img').each(function () { - content(this) + content('figure img').each((_, el) => { + content(el) .parent() - .html(``); + .html(``); }); content('.inline-post').remove(); diff --git a/lib/routes/ngocn2/index.ts b/lib/routes/ngocn2/index.ts index 7a1ea5819..69635ec4c 100644 --- a/lib/routes/ngocn2/index.ts +++ b/lib/routes/ngocn2/index.ts @@ -67,8 +67,8 @@ async function handler(ctx) { const content = load(detailResponse.data); - content('.gatsby-resp-image-link').each(function () { - content(this).html(``); + content('.gatsby-resp-image-link').each((_, el) => { + content(el).html(``); }); item.description = content('.article__content').html(); diff --git a/lib/routes/njxzc/lib.ts b/lib/routes/njxzc/lib.ts index 632f580e8..e9d92d17b 100644 --- a/lib/routes/njxzc/lib.ts +++ b/lib/routes/njxzc/lib.ts @@ -71,15 +71,15 @@ async function handler() { } else { const $content = $('.wp_articlecontent'); // Convert wp_pdf_player iframes to download links - $content.find('.wp_pdf_player').each(function () { - const $iframe = $(this); + $content.find('.wp_pdf_player').each((_, el) => { + const $iframe = $(el); const pdfSrc = $iframe.attr('pdfsrc') || ''; const pdfUrl = pdfSrc.startsWith('http') ? pdfSrc : new URL(pdfSrc, host).href; $iframe.replaceWith(`

附件下载

`); }); // Fix relative URLs - $content.find('a').each(function () { - const $a = $(this); + $content.find('a').each((_, el) => { + const $a = $(el); const href = $a.attr('href'); if (href && !href.startsWith('http')) { $a.attr('href', new URL(href, host).href); diff --git a/lib/routes/njxzc/utils/index.ts b/lib/routes/njxzc/utils/index.ts index 761487a6e..7cfc716d9 100644 --- a/lib/routes/njxzc/utils/index.ts +++ b/lib/routes/njxzc/utils/index.ts @@ -36,15 +36,15 @@ async function getNoticeList(ctx, url, host, titleSelector, dateSelector, conten } else { const $content = $(contentSelector.content); // Convert wp_pdf_player iframes to download links - $content.find('.wp_pdf_player').each(function () { - const $iframe = $(this); + $content.find('.wp_pdf_player').each((_, el) => { + const $iframe = $(el); const pdfSrc = $iframe.attr('pdfsrc') || ''; const pdfUrl = pdfSrc.startsWith('http') ? pdfSrc : new URL(pdfSrc, host).href; $iframe.replaceWith(`

附件下载

`); }); // Fix relative URLs - $content.find('a').each(function () { - const $a = $(this); + $content.find('a').each((_, el) => { + const $a = $(el); const href = $a.attr('href'); if (href && !href.startsWith('http')) { $a.attr('href', new URL(href, host).href); diff --git a/lib/routes/nwnu/routes/lib/embed-resource.ts b/lib/routes/nwnu/routes/lib/embed-resource.ts index de002b363..974738ca1 100644 --- a/lib/routes/nwnu/routes/lib/embed-resource.ts +++ b/lib/routes/nwnu/routes/lib/embed-resource.ts @@ -3,8 +3,8 @@ import { load } from 'cheerio'; export function processEmbedPDF(baseurl: string, html: string) { const $ = load(html); - $('div.wp_pdf_player').each(function () { - const $div = $(this); + $('div.wp_pdf_player').each((_, el) => { + const $div = $(el); const pdfsrc = $div.attr('pdfsrc') || ''; const downloadUrl = new URL(pdfsrc, baseurl).href; const newDiv = `

点击下载 PDF 文件资源

`; diff --git a/lib/routes/nytimes/daily-briefing-chinese.tsx b/lib/routes/nytimes/daily-briefing-chinese.tsx index cb0d28e8e..712b93166 100644 --- a/lib/routes/nytimes/daily-briefing-chinese.tsx +++ b/lib/routes/nytimes/daily-briefing-chinese.tsx @@ -70,8 +70,8 @@ async function handler() { const images = detailResponse.data.match(/"url":"[^{}]+","name":"articleLarge"/g).map((e) => JSON.parse(`{${e}}`).url); let i = 0; - content('figure').each(function () { - content(this).html( + content('figure').each((_, el) => { + content(el).html( renderToString(
diff --git a/lib/routes/odaily/activity.ts b/lib/routes/odaily/activity.ts index b414ba934..554b90bfa 100644 --- a/lib/routes/odaily/activity.ts +++ b/lib/routes/odaily/activity.ts @@ -56,10 +56,10 @@ async function handler(ctx) { const content = load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]); - content('img').each(function () { - content(this).attr( + content('img').each((_, el) => { + content(el).attr( 'src', - content(this) + content(el) .attr('src') .replaceAll(String.raw`\"`, '') ); diff --git a/lib/routes/odaily/user.ts b/lib/routes/odaily/user.ts index b0ec1cf11..1a5e95b7d 100644 --- a/lib/routes/odaily/user.ts +++ b/lib/routes/odaily/user.ts @@ -60,10 +60,10 @@ async function handler(ctx) { const content = load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); - content('img').each(function () { - content(this).attr( + content('img').each((_, el) => { + content(el).attr( 'src', - content(this) + content(el) .attr('src') .replaceAll(String.raw`\"`, '') ); diff --git a/lib/routes/onet/utils.ts b/lib/routes/onet/utils.ts index d90710018..f43968e9c 100644 --- a/lib/routes/onet/utils.ts +++ b/lib/routes/onet/utils.ts @@ -18,9 +18,7 @@ const parseArticleContent = ($) => { const content = $('[itemprop="articleBody"]'); $('*') .contents() - .filter(function () { - return this.nodeType === 8; - }) + .filter((_, el) => el.nodeType === 8) .remove(); content.find('aside').remove(); content.find('.videoPlayerContainer').remove(); diff --git a/lib/routes/oreno3d/get-sec-page-data.ts b/lib/routes/oreno3d/get-sec-page-data.ts index a99feda25..4bc1f5daa 100644 --- a/lib/routes/oreno3d/get-sec-page-data.ts +++ b/lib/routes/oreno3d/get-sec-page-data.ts @@ -30,29 +30,29 @@ async function sync_detail(link) { // 存为列表 $(sec_page_selector) .find(author_selector) - .each(function (i) { - authors[i] = $(this).text(); + .each((i, el) => { + authors[i] = $(el).text(); authors[i].replace(' ', ''); // 去空格 authors[i].trim(); // 去首尾空格 }); $(sec_page_selector) .find(origins_selector) - .each(function (i) { - origins[i] = $(this).text(); + .each((i, el) => { + origins[i] = $(el).text(); origins[i].replace(' ', ''); origins[i].trim(); }); $(sec_page_selector) .find(characters_selector) - .each(function (i) { - characters[i] = $(this).text(); + .each((i, el) => { + characters[i] = $(el).text(); characters[i].replace(' ', ''); characters[i].trim(); }); $(sec_page_selector) .find(tags_selector) - .each(function (i) { - tags[i] = $(this).text(); + .each((i, el) => { + tags[i] = $(el).text(); tags[i].replace(' ', ''); tags[i].trim(); }); diff --git a/lib/routes/qq88/index.ts b/lib/routes/qq88/index.ts index d446c9bd2..31d75295b 100644 --- a/lib/routes/qq88/index.ts +++ b/lib/routes/qq88/index.ts @@ -67,8 +67,8 @@ async function handler(ctx) { item.enclosure_url = links.eq(-1).attr('href'); item.description = `
`; - links.each(function () { - item.description += `
  • ${content(this).text()}
  • `; + links.each((_, el) => { + item.description += `
  • ${content(el).text()}
  • `; }); return item; diff --git a/lib/routes/researchgate/publications.ts b/lib/routes/researchgate/publications.ts index 49e8f3f18..296640a03 100644 --- a/lib/routes/researchgate/publications.ts +++ b/lib/routes/researchgate/publications.ts @@ -64,8 +64,8 @@ async function handler(ctx) { const authors = []; - content('meta[property="citation_author"]').each(function () { - authors.push(content(this).attr('content')); + content('meta[property="citation_author"]').each((_, el) => { + authors.push(content(el).attr('content')); }); item.author = authors.join(', '); diff --git a/lib/routes/right/forum.ts b/lib/routes/right/forum.ts index 0cf8a887b..2bc77169e 100644 --- a/lib/routes/right/forum.ts +++ b/lib/routes/right/forum.ts @@ -38,8 +38,8 @@ async function handler(ctx) { const $ = load(response.data); - $('a[title="隐藏置顶帖"]').each(function () { - $(this).parents('tbody').remove(); + $('a[title="隐藏置顶帖"]').each((_, el) => { + $(el).parents('tbody').remove(); }); let items = $('.s') diff --git a/lib/routes/rsc/journal.tsx b/lib/routes/rsc/journal.tsx index 7deb5b384..71755f674 100644 --- a/lib/routes/rsc/journal.tsx +++ b/lib/routes/rsc/journal.tsx @@ -51,9 +51,9 @@ async function handler(ctx) { let $ = load(response); - $('div.capsule__article-image').each(function () { - const image = $(this).find('img').prop('data-original'); - $(this).replaceWith( + $('div.capsule__article-image').each((_, el) => { + const image = $(el).find('img').prop('data-original'); + $(el).replaceWith( renderToString( image ? (
    diff --git a/lib/routes/ruancan/utils.ts b/lib/routes/ruancan/utils.ts index 9b4365a7b..9c8c335d2 100644 --- a/lib/routes/ruancan/utils.ts +++ b/lib/routes/ruancan/utils.ts @@ -39,14 +39,14 @@ const fetchFeed = async (ctx, currentUrl) => { content('.entry-copyright').remove(); - content('.entry-content div').each(function () { - if (/^ruanc-\d+/.test(content(this).attr('id'))) { - content(this).remove(); + content('.entry-content div').each((_, el) => { + if (/^ruanc-\d+/.test(content(el).attr('id'))) { + content(el).remove(); } }); - content('figure').each(function () { - content(this).html(``); + content('figure').each((_, el) => { + content(el).html(``); }); item.description = content('.entry-content').html(); diff --git a/lib/routes/saraba1st/digest.tsx b/lib/routes/saraba1st/digest.tsx index 027ba7405..4eac1717b 100644 --- a/lib/routes/saraba1st/digest.tsx +++ b/lib/routes/saraba1st/digest.tsx @@ -84,16 +84,16 @@ async function fetchContent(url) { const stubS = subind('
    '); subind('#postlist') .find('div[id*="post_"] ') - .each(function () { - if (subind(this).find('td[id*="postmessage_"]').length > 0) { + .each((_, el) => { + if (subind(el).find('td[id*="postmessage_"]').length > 0) { const section = renderToString( ); @@ -101,8 +101,8 @@ async function fetchContent(url) { } }); - stubS.find('img').each(function () { - const img = subind(this); + stubS.find('img').each((_, el) => { + const img = subind(el); const file = img.attr('file'); if (file) { img.attr('src', file); diff --git a/lib/routes/sensortower/blog.ts b/lib/routes/sensortower/blog.ts index bf5c6533c..01a483d26 100644 --- a/lib/routes/sensortower/blog.ts +++ b/lib/routes/sensortower/blog.ts @@ -67,10 +67,10 @@ async function handler(ctx) { content('h5').parent().remove(); content('div[data-testid="Text-embedded-entry-block"]').remove(); - content('img').each(function () { - const image = (content(this).attr('srcset') ?? content(this).attr('src')).split('?w=')[0]; + content('img').each((_, el) => { + const image = (content(el).attr('srcset') ?? content(el).attr('src')).split('?w=')[0]; - content(this).replaceWith(renderDescription({ image })); + content(el).replaceWith(renderDescription({ image })); }); item.title = detail.title; diff --git a/lib/routes/shoppingdesign/posts.ts b/lib/routes/shoppingdesign/posts.ts index 4a4595a61..a4702417d 100644 --- a/lib/routes/shoppingdesign/posts.ts +++ b/lib/routes/shoppingdesign/posts.ts @@ -44,8 +44,8 @@ async function handler() { const response = await got(`${link}?sn_f=1`); const $ = load(response.data); const article = $('.left article .htmlview'); - article.find('d-image').each(function () { - $(this).replaceWith(``); + article.find('d-image').each((_, el) => { + $(el).replaceWith(``); }); return { diff --git a/lib/routes/sinchew/index.tsx b/lib/routes/sinchew/index.tsx index e14e767cb..65873e01d 100644 --- a/lib/routes/sinchew/index.tsx +++ b/lib/routes/sinchew/index.tsx @@ -60,12 +60,12 @@ async function handler(ctx) { content('.ads-frame, .read-more-msg').remove(); - content('figure').each(function () { - content(this).replaceWith( + content('figure').each((_, el) => { + content(el).replaceWith( renderToString(
    - -
    {content(this).find('figcaption').text()}
    + +
    {content(el).find('figcaption').text()}
    ) ); diff --git a/lib/routes/subhd/index.ts b/lib/routes/subhd/index.ts index 926c2855b..e81600b29 100644 --- a/lib/routes/subhd/index.ts +++ b/lib/routes/subhd/index.ts @@ -41,8 +41,8 @@ async function handler(ctx) { const $ = load(response.data); - $('.align-middle').each(function () { - $(this).removeClass('link-dark'); + $('.align-middle').each((_, el) => { + $(el).removeClass('link-dark'); }); let items = $('.link-dark') diff --git a/lib/routes/swissinfo/index.ts b/lib/routes/swissinfo/index.ts index 2de079e86..f4935f3bf 100644 --- a/lib/routes/swissinfo/index.ts +++ b/lib/routes/swissinfo/index.ts @@ -78,8 +78,8 @@ async function handler(ctx) { content('.si-detail__content .si-teaser').remove(); content('.show-for-sr, time, address, .si-detail__translation').remove(); - content('picture').each(function () { - content(this).html(``); + content('picture').each((_, el) => { + content(el).html(``); }); item.description = content('.si-detail__content').html(); diff --git a/lib/routes/telegram/channel.ts b/lib/routes/telegram/channel.ts index 10d433fba..878dabd69 100644 --- a/lib/routes/telegram/channel.ts +++ b/lib/routes/telegram/channel.ts @@ -658,13 +658,13 @@ async function handler(ctx) { if (msgTypes.includes(UNSUPPORTED)) { if (unsupportedNodes.length) { unsupportedHtml += '
    '; - unsupportedNodes.find('.message_media_not_supported_label').each(function () { - const $this = $(this); + unsupportedNodes.find('.message_media_not_supported_label').each((_, el) => { + const $this = $(el); unsupportedTitle += $this.text(); unsupportedHtml += `

    ${$this.text()}

    `; }); - unsupportedNodes.find('.message_media_view_in_telegram').each(function () { - const $this = $(this); + unsupportedNodes.find('.message_media_view_in_telegram').each((_, el) => { + const $this = $(el); unsupportedHtml += $this.attr('href') ? `

    ${$this.text()}

    ` : `

    ${$this.text()}

    `; }); unsupportedHtml += '
    '; diff --git a/lib/routes/thenewslens/index.ts b/lib/routes/thenewslens/index.ts index c8d393002..e4b3c71d0 100644 --- a/lib/routes/thenewslens/index.ts +++ b/lib/routes/thenewslens/index.ts @@ -59,10 +59,10 @@ async function handler(ctx) { content('a[data-sk="tooltip_parent"]').parent().remove(); content('.ad-section, .recommender-title, .navigation-content').remove(); - content('.article-img-container').each(function () { - content(this).replaceWith( + content('.article-img-container').each((_, el) => { + content(el).replaceWith( renderDescription({ - image: content(this).find('img')?.attr('data-srcset').split('?')[0] ?? undefined, + image: content(el).find('img')?.attr('data-srcset').split('?')[0] ?? undefined, }) ); }); diff --git a/lib/routes/wechat/announce.ts b/lib/routes/wechat/announce.ts index 37b124dae..c1cbc2c66 100644 --- a/lib/routes/wechat/announce.ts +++ b/lib/routes/wechat/announce.ts @@ -37,8 +37,8 @@ async function handler() { const $ = load(htmlString); const announceList = []; - $('.mp_news_list > .mp_news_item').each(function () { - const $item = $(this); + $('.mp_news_list > .mp_news_item').each((_, el) => { + const $item = $(el); const $link = $item.find('a'); const time = $item.find('.read_more').text(); const title = $item.find('strong').text(); diff --git a/lib/routes/wenku8/chapter.ts b/lib/routes/wenku8/chapter.ts index 7e1046de2..980b33a69 100644 --- a/lib/routes/wenku8/chapter.ts +++ b/lib/routes/wenku8/chapter.ts @@ -40,10 +40,10 @@ async function handler(ctx) { const chapter_item = []; - $('.ccss>a').each(function () { + $('.ccss>a').each((_, el) => { chapter_item.push({ - title: $(this).text(), - link: `https://www.wenku8.net/novel/${index}/${id}/` + $(this).attr('href'), + title: $(el).text(), + link: `https://www.wenku8.net/novel/${index}/${id}/` + $(el).attr('href'), }); }); diff --git a/lib/routes/whu/util.ts b/lib/routes/whu/util.ts index 12e5ca908..a95d883c2 100644 --- a/lib/routes/whu/util.ts +++ b/lib/routes/whu/util.ts @@ -48,9 +48,9 @@ const getItemDetail = async (item, rootUrl) => { // Missing the `src` properties for the images. // The `src` property should be replaced with the value of `orisrc` to show the image. // Replace images in the content with custom JSX template. - content('p.vsbcontent_img').each(function () { - const image = content(this).find('img'); - content(this).replaceWith( + content('p.vsbcontent_img').each((_, el) => { + const image = content(el).find('img'); + content(el).replaceWith( renderDescription({ image: { src: new URL(image.prop('orisrc'), rootUrl).href, @@ -63,8 +63,8 @@ const getItemDetail = async (item, rootUrl) => { // Missing the `src` properties for the videos. // The `src` property should be replaced with the value of `vurl` to play the video. // Replace videos in the content with custom JSX template. - content('script[name="_videourl"]').each(function () { - const video = content(this); + content('script[name="_videourl"]').each((_, el) => { + const video = content(el); video.replaceWith( renderDescription({ video: { diff --git a/lib/routes/wsj/utils.tsx b/lib/routes/wsj/utils.tsx index 109c3a785..4cba5ccac 100644 --- a/lib/routes/wsj/utils.tsx +++ b/lib/routes/wsj/utils.tsx @@ -42,8 +42,8 @@ const parseArticle = (item) => article.find('.bylineWrap').each((i, e) => { $(e) .find('p') - .each(function () { - $(this).replaceWith($(this).html()); + .each((_, el) => { + $(el).replaceWith($(el).html()); }); }); diff --git a/lib/routes/wzu/news.ts b/lib/routes/wzu/news.ts index 2f2ffe7d7..e73e22618 100644 --- a/lib/routes/wzu/news.ts +++ b/lib/routes/wzu/news.ts @@ -39,10 +39,10 @@ async function loadContent(link) { // 图片相对链接处理 $('img').attr('src', (n, v) => new URL(v, baseUrl).href); // 视频相对链接处理,替换原有播放方法 showVsbVideo - $('.vsbcontent_video').each(function () { - const u1 = $(this).find('script').attr('vurl'); + $('.vsbcontent_video').each((_, el) => { + const u1 = $(el).find('script').attr('vurl'); videoUrl = new URL(u1, baseUrl).href; - return $(this) + $(el) .html('') .html(); }); diff --git a/lib/routes/xjtu/dean.ts b/lib/routes/xjtu/dean.ts index 922259252..d3d43b867 100644 --- a/lib/routes/xjtu/dean.ts +++ b/lib/routes/xjtu/dean.ts @@ -16,8 +16,8 @@ const parseContent = (htmlString) => { .map((element) => $(element).text().trim()); const content = $('[id^="vsb_content"]'); - $('form > div > ul a').each(function () { - $(this).appendTo(content); + $('form > div > ul a').each((_, el) => { + $(el).appendTo(content); $('
    ').appendTo(content); }); diff --git a/lib/routes/xjtu/ee-jzxx.ts b/lib/routes/xjtu/ee-jzxx.ts index 8d8086a3b..d1103320b 100644 --- a/lib/routes/xjtu/ee-jzxx.ts +++ b/lib/routes/xjtu/ee-jzxx.ts @@ -76,8 +76,8 @@ async function handler(ctx) { const description = content('div.art-body.wow.fadeInUp') .clone() // 创建副本防止修改原始内容 .find('ul li') // 定位到附件列表项 - .each(function () { - const $li = $(this); + .each((_, el) => { + const $li = $(el); const newText = $li.html()?.replaceAll(/已下载[\s\S]*?<\/span>次/g, '') ?? ''; $li.html(newText.replace(/<\/a>\s*$/, '')); }) diff --git a/lib/routes/xmnn/epaper.ts b/lib/routes/xmnn/epaper.ts index 3ce7c1dbe..ceec1c717 100644 --- a/lib/routes/xmnn/epaper.ts +++ b/lib/routes/xmnn/epaper.ts @@ -70,8 +70,8 @@ async function handler(ctx) { $('#pdfsrc').remove(); $('.bigImg, .smallImg').remove(); - $('a img').each(function () { - $(this).parent().remove(); + $('a img').each((_, el) => { + $(el).parent().remove(); }); let items = $('.br1, .br2, .titss') diff --git a/lib/routes/xyu/notices.ts b/lib/routes/xyu/notices.ts index 02b3f0352..bc700b68c 100644 --- a/lib/routes/xyu/notices.ts +++ b/lib/routes/xyu/notices.ts @@ -88,8 +88,8 @@ async function handler() { if (content) { const $content = load(content); - $content('a').each(function () { - const a = $(this); + $content('a').each((_, el) => { + const a = $(el); const href = a.attr('href'); if (href && !href.startsWith('http')) { a.attr('href', new URL(href, baseUrl).href); diff --git a/lib/routes/ycwb/index.tsx b/lib/routes/ycwb/index.tsx index 283c17f13..7f8682620 100644 --- a/lib/routes/ycwb/index.tsx +++ b/lib/routes/ycwb/index.tsx @@ -82,17 +82,15 @@ async function handler(ctx) { const $comments = content('.main_article') .contents() - .filter(function () { - return this.nodeType === 8; - }); - $comments.each(function () { + .filter((_, el) => el.nodeType === 8); + $comments.each((_, el) => { // Remove useless comments - if (/audioPlayer|audio-box/.test(this.data)) { - this.data = ''; + if (/audioPlayer|audio-box/.test(el.data)) { + el.data = ''; } // Filter author from comments - if (/author/.test(this.data)) { - item.author = this.data.split('')[1].split('')[0]; + if (/author/.test(el.data)) { + item.author = el.data.split('')[1].split('')[0]; } }); diff --git a/lib/routes/zcool/discover.ts b/lib/routes/zcool/discover.ts index 46b6b2e40..7777f7144 100644 --- a/lib/routes/zcool/discover.ts +++ b/lib/routes/zcool/discover.ts @@ -270,12 +270,12 @@ async function handler(ctx) { const videos = detailResponse.data.match(/source: '(https:\/\/video\.zcool\.cn\/.*)',/g); if (videos) { - content('.video-content-box').each(function (i) { + content('.video-content-box').each((i, el) => { if (i >= videos.length) { return; } - content(this).append( + content(el).append( renderDescription({ video: videos[i].match(/source: '(https:\/\/video\.zcool\.cn\/.*)'/)[1], })