mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Skip redirected cards
This commit is contained in:
parent
c9a8694df8
commit
8c3ed109f1
@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user