Skip to content

Commit

Permalink
feat: video filter support space page home part
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Apr 4, 2024
1 parent ef99f1b commit c12a3a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CHANGELOG

## 3.3.5
## 3.4.0

- 新增:视频过滤支持空间页(UP主投稿列表、视频合集列表)
- 新增:视频过滤支持空间页(UP主主页、投稿列表、视频合集列表)
- 修复:标题关键词白名单失效bug

## 3.3.4
Expand Down
32 changes: 29 additions & 3 deletions src/filters/videoFilter/pages/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ if (isPageSpace()) {
// 构建SelectorFunc
const submitSelectorFunc: VideoSelectorFunc = {
duration: (video: Element): string | null => {
const duration = video.querySelector('span.length')?.textContent
const duration = video.querySelector('span.length')?.textContent?.trim()
return duration ? duration : null
},
titleKeyword: (video: Element): string | null => {
const titleKeyword =
video.querySelector('a.title')?.textContent || video.querySelector('a.title')?.getAttribute('title')
video.querySelector('a.title')?.textContent?.trim() ||
video.querySelector('a.title')?.getAttribute('title')?.trim()
return titleKeyword ? titleKeyword : null
},
bvid: (video: Element): string | null => {
const href = video.querySelector('a.title')?.getAttribute('href')
const href = video.querySelector('a.title')?.getAttribute('href')?.trim()
return href ? matchBvid(href) : null
},
}
const homeSelectorFunc = submitSelectorFunc
const collectionSelectorFunc = submitSelectorFunc

// 检测视频列表
Expand All @@ -38,6 +40,12 @@ if (isPageSpace()) {
return
}
try {
// 主页视频
if (location.pathname.match(/^\/\d+$/)) {
const homeVideos = [...videoListContainer.querySelectorAll<HTMLElement>(`#page-index .small-item`)]
homeVideos.length && coreFilterInstance.checkAll(homeVideos, false, homeSelectorFunc)
debug(`checkVideoList check ${homeVideos.length} home video`)
}
// 投稿视频
if (location.pathname.match(/^\/\d+\/video$/)) {
const submitVideos = [
Expand Down Expand Up @@ -152,6 +160,21 @@ if (isPageSpace()) {
//=======================================================================================
// 构建UI菜单

// 样式补丁,用于主页视频列表过滤后对齐视频
const patchCSS = `
@media (min-width: 1420px) {
#page-index .video .content .small-item:nth-child(4n+1) {padding-left: 7px !important; padding-right: 7px !important;}
#page-index .video .content .small-item:nth-child(4n+4) {padding-left: 7px !important; padding-right: 7px !important;}
#page-index .video .content .small-item:nth-child(5n+5) {padding-left: 7px !important; padding-right: 7px !important;}
#page-index .video .content .small-item:nth-child(5n+1) {padding-left: 7px !important; padding-right: 7px !important;}
#page-index .video .content .small-item:nth-child(13),
#page-index .video .content .small-item:nth-child(14),
#page-index .video .content .small-item:nth-child(15) {display: block}
}
#page-index .video .content .small-item:nth-child(4n+1) {padding-left: 7px !important; padding-right: 7px !important;}
#page-index .video .content .small-item:nth-child(4n+4) {padding-left: 7px !important; padding-right: 7px !important;}
.small-item {padding: 10px 7px !important;}`

// UI组件, 时长过滤
const durationItems = [
// 启用 空间页时长过滤
Expand All @@ -164,6 +187,7 @@ if (isPageSpace()) {
callback: () => {
spaceDurationAction.disable()
},
itemCSS: patchCSS,
}),
// 设定最低时长
new NumberItem({
Expand Down Expand Up @@ -193,6 +217,7 @@ if (isPageSpace()) {
callback: () => {
spaceTitleKeywordAction.disable()
},
itemCSS: patchCSS,
}),
// 编辑 标题关键词黑名单
new ButtonItem({
Expand Down Expand Up @@ -225,6 +250,7 @@ if (isPageSpace()) {
isContextMenuBvidEnable = false
spaceBvidAction.disable()
},
itemCSS: patchCSS,
}),
// 编辑 BV号黑名单
new ButtonItem({
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
userscript: {
name: 'bilibili 页面净化大师',
namespace: 'http://tampermonkey.net/',
version: '3.3.5',
version: '3.4.0',
description:
'净化 B站/哔哩哔哩 网页元素,去广告,BV号转AV号,播放器净化,过滤视频,过滤评论,提供300+项功能,定制自己的B站页面',
author: 'festoney8',
Expand Down

0 comments on commit c12a3a8

Please sign in to comment.