Skip redirected cards

This commit is contained in:
the1812 2025-02-24 22:23:36 +08:00
parent c9a8694df8
commit 8c3ed109f1

View File

@ -8,6 +8,11 @@ const getBvidFromElement = (element: Element) => {
return bvid 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) => { const redirect = (element: Element, watchlaterItem: RawWatchlaterItem) => {
try { try {
const { bvid, cid, pages } = watchlaterItem const { bvid, cid, pages } = watchlaterItem
@ -45,9 +50,12 @@ const entry: ComponentEntry = async ({ settings }) => {
} }
const tryRedirect = (element: Element) => { const tryRedirect = (element: Element) => {
if (isRedirected(element)) {
return
}
const bvid = getBvidFromElement(element) const bvid = getBvidFromElement(element)
if (bvid === undefined) { if (bvid === undefined) {
console.warn('bvid not found for', element) console.warn('bvid not found for', element.outerHTML)
return return
} }
const listItem = list.find(it => it.bvid === bvid) const listItem = list.find(it => it.bvid === bvid)
@ -55,6 +63,7 @@ const entry: ComponentEntry = async ({ settings }) => {
console.warn('bvid no match for', bvid) console.warn('bvid no match for', bvid)
return return
} }
console.log('redirect for', bvid)
redirect(element, listItem) redirect(element, listItem)
} }
@ -72,9 +81,11 @@ const entry: ComponentEntry = async ({ settings }) => {
const hasVideoCardChange = [...r.addedNodes].some( const hasVideoCardChange = [...r.addedNodes].some(
node => node =>
node instanceof HTMLElement && node instanceof HTMLElement &&
(node.classList.contains('bili-video-card__wrap') || ['bili-video-card__wrap', 'video-card', 'watchlater-list-container'].some(value =>
node.classList.contains('watchlater-list-container')), node.classList.contains(value),
),
) )
// console.log({ nodes: r.addedNodes, hasVideoCardChange })
if (hasVideoCardChange) { if (hasVideoCardChange) {
runRedirect() runRedirect()
} }