From 8c3ed109f10997d3717c5b88692fd96fd2932dd7 Mon Sep 17 00:00:00 2001 From: the1812 Date: Mon, 24 Feb 2025 22:23:36 +0800 Subject: [PATCH] Skip redirected cards --- .../utils/watchlater-redirect/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/registry/lib/components/utils/watchlater-redirect/index.ts b/registry/lib/components/utils/watchlater-redirect/index.ts index a5dc6251f..64fd6779c 100644 --- a/registry/lib/components/utils/watchlater-redirect/index.ts +++ b/registry/lib/components/utils/watchlater-redirect/index.ts @@ -8,6 +8,11 @@ const getBvidFromElement = (element: Element) => { return bvid } +const isRedirected = (element: Element) => { + const pic = element.querySelector('.av-pic, .bili-cover-card') as HTMLAnchorElement + return /video\/BV/.test(pic.href) +} + const redirect = (element: Element, watchlaterItem: RawWatchlaterItem) => { try { const { bvid, cid, pages } = watchlaterItem @@ -45,9 +50,12 @@ const entry: ComponentEntry = async ({ settings }) => { } const tryRedirect = (element: Element) => { + if (isRedirected(element)) { + return + } const bvid = getBvidFromElement(element) if (bvid === undefined) { - console.warn('bvid not found for', element) + console.warn('bvid not found for', element.outerHTML) return } const listItem = list.find(it => it.bvid === bvid) @@ -55,6 +63,7 @@ const entry: ComponentEntry = async ({ settings }) => { console.warn('bvid no match for', bvid) return } + console.log('redirect for', bvid) redirect(element, listItem) } @@ -72,9 +81,11 @@ const entry: ComponentEntry = async ({ settings }) => { const hasVideoCardChange = [...r.addedNodes].some( node => node instanceof HTMLElement && - (node.classList.contains('bili-video-card__wrap') || - node.classList.contains('watchlater-list-container')), + ['bili-video-card__wrap', 'video-card', 'watchlater-list-container'].some(value => + node.classList.contains(value), + ), ) + // console.log({ nodes: r.addedNodes, hasVideoCardChange }) if (hasVideoCardChange) { runRedirect() }