Skip to content

Commit

Permalink
feat: video page ending related video filter
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed May 26, 2024
1 parent 536d6d5 commit 85f4173
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- 新增:稍后再看列表页,双列布局
- 新增:修复字体(直播页、热门页、空间页、稍后再看)
- 新增:播放页 支持筛选视频结束后推荐视频
- 更新:直播页净化功能,适配网页变动

## 3.6.1
Expand Down
69 changes: 67 additions & 2 deletions src/filters/videoFilter/pages/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import coreFilterInstance, { VideoSelectorFunc } from '../filters/core'
import { ButtonItem, CheckboxItem, NumberItem } from '../../../components/item'
import { Group } from '../../../components/group'
import { isPagePlaylist, isPageVideo } from '../../../utils/page-type'
import { matchBvid, showEle, waitForEle } from '../../../utils/tool'
import { hideEle, isEleHide, matchBvid, showEle, waitForEle } from '../../../utils/tool'
import {
BvidAction,
DurationAction,
Expand All @@ -24,7 +24,8 @@ let isContextMenuUploaderEnable = false
let isContextMenuBvidEnable = false
// 接下来播放是否免过滤
let isNextPlayWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-next-play-whitelist-filter-status', true)

// 视频结束后播放器内推荐是否免过滤
let isEndingWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-ending-whitelist-filter-status', true)
if (isPageVideo() || isPagePlaylist()) {
let videoListContainer: HTMLElement
// 构建SelectorFunc
Expand Down Expand Up @@ -143,6 +144,52 @@ if (isPageVideo() || isPagePlaylist()) {
}
}

// 视频结束后筛选播放器内视频
const watchPlayerEnding = () => {
if (isEndingWhitelistEnable) {
return
}
const video = document.querySelector('video')
if (!video) {
return
}
const check = () => {
const rightList = document.querySelectorAll<HTMLElement>(`.next-play .video-page-card-small,
.next-play .video-page-operator-card-small,
.rec-list .video-page-card-small,
.rec-list .video-page-operator-card-small,
.recommend-video-card`)
const blacklistVideoTitle = new Set<string>()
rightList.forEach((video: HTMLElement) => {
if (isEleHide(video)) {
const title =
video.querySelector('.info > a p')?.getAttribute('title') ||
video.querySelector('.info > a p')?.textContent
title && blacklistVideoTitle.add(title)
}
})
let cnt = 0
const endingInterval = setInterval(() => {
const endingVideos = document.querySelectorAll<HTMLElement>('.bpx-player-ending-related-item')
if (endingVideos.length > 0) {
endingVideos.forEach((video: HTMLElement) => {
const title = video.querySelector('.bpx-player-ending-related-item-title')?.textContent?.trim()
if (title && blacklistVideoTitle.has(title)) {
hideEle(video)
}
})
clearInterval(endingInterval)
} else {
cnt++
if (cnt > 100) {
clearInterval(endingInterval)
}
}
}, 10)
}
video.ended ? check() : video.addEventListener('ended', check)
}

try {
// 监听视频列表出现
waitForEle(document, '#reco_list, .recommend-list-container', (node: Node): boolean => {
Expand All @@ -157,6 +204,8 @@ if (isPageVideo() || isPagePlaylist()) {
watchVideoListContainer()
}
})
// 监听视频播放结束,筛选播放器内视频推荐
document.addEventListener('DOMContentLoaded', watchPlayerEnding)
} catch (err) {
error(err)
error(`watch video list ERROR`)
Expand Down Expand Up @@ -389,6 +438,22 @@ if (isPageVideo() || isPagePlaylist()) {
checkVideoList(true)
},
}),
// 视频播放结束推荐 免过滤
new CheckboxItem({
itemID: 'video-ending-whitelist-filter-status',
description: '视频播放结束推荐 免过滤',
defaultStatus: true,
itemFunc: () => {
isEndingWhitelistEnable = true
document
.querySelectorAll<HTMLElement>('.bpx-player-ending-related-item')
.forEach((e: HTMLElement) => showEle(e))
},
callback: () => {
isEndingWhitelistEnable = false
watchPlayerEnding()
},
}),
// 启用 播放页UP主白名单
new CheckboxItem({
itemID: videoUploaderWhitelistAction.statusKey,
Expand Down

0 comments on commit 85f4173

Please sign in to comment.