Skip to content

Commit

Permalink
Fix watchlater redirect (fix #1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Apr 24, 2021
1 parent 77ae983 commit 2c67c9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion min/watchlater.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions src/utils/watchlater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ if (settings.watchLaterRedirectPage) {
return
}
const redirect = (item: Element, index: number) => {
const watchlaterItem = list[index]
const bvid = watchlaterItem.bvid
const cid = watchlaterItem.cid
const pages = watchlaterItem.pages
const page = cid === 0 ? 1 : pages.find(p => p.cid === cid)!.page
const url = page > 1 ? `https://www.bilibili.com/video/${bvid}?p=${page}` : `https://www.bilibili.com/video/${bvid}`
const pic = item.querySelector('.av-pic') as HTMLAnchorElement
pic.target = '_blank'
pic.href = url
const title = item.querySelector('.av-about .t') as HTMLAnchorElement
title.target = '_blank'
title.href = url
try {
const watchlaterItem = list[index]
const bvid = watchlaterItem.bvid
const cid = watchlaterItem.cid
const pages = watchlaterItem.pages
const page = pages.find(p => p.cid === cid)?.page ?? 1
const url = page > 1 ? `https://www.bilibili.com/video/${bvid}?p=${page}` : `https://www.bilibili.com/video/${bvid}`
const pic = item.querySelector('.av-pic') as HTMLAnchorElement
pic.target = '_blank'
pic.href = url
const title = item.querySelector('.av-about .t') as HTMLAnchorElement
title.target = '_blank'
title.href = url
} catch (error) {
console.error(`[watchlater redirect] error at index ${index}`, item, error)
}
}
const runRedirect = () => {
const avItems = listBox.querySelectorAll('.av-item')
Expand Down

0 comments on commit 2c67c9e

Please sign in to comment.