Skip to content

Commit bf4552d

Browse files
committed
fix: dyn filter header invalid
1 parent 3b461fa commit bf4552d

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- 新增:评论区 隐藏大表情弹框
66
- 新增:动态过滤支持白名单
7+
- 修复:动态过滤顶栏动态列表失效问题
78
- 更新:排除页面列表
89
- 更新:部分功能细节
910

src/modules/filters/variety/dynamic/pages/dynamic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export const dynamicFilterDynamicGroups: Group[] = [
338338
type: 'switch',
339339
id: GM_KEYS.black.content.statusKey,
340340
name: '启用 动态内容关键词过滤',
341-
description: ['不含动态内视频标题'],
341+
description: ['不覆盖动态内视频标题'],
342342
noStyle: true,
343343
enableFn: () => {
344344
mainFilter.dynContentFilter.enable()
@@ -437,7 +437,7 @@ export const dynamicFilterDynamicGroups: Group[] = [
437437
type: 'switch',
438438
id: GM_KEYS.white.content.statusKey,
439439
name: '启用 动态内容关键词白名单',
440-
description: ['不含动态内视频标题'],
440+
description: ['不覆盖动态内视频标题'],
441441
noStyle: true,
442442
enableFn: () => {
443443
mainFilter.dynContentWhiteFilter.enable()

src/modules/filters/variety/dynamic/pages/header.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IMainFilter, SelectorResult, SubFilterPair } from '@/types/filter'
44
import { debugFilter as debug, error } from '@/utils/logger'
55
import { BiliCleanerStorage } from '@/utils/storage'
66
import { DynContentFilter, DynUploaderFilter, DynVideoTitleFilter } from '../subFilters/black'
7+
import { DynContentWhiteFilter, DynVideoTitleWhiteFilter } from '../subFilters/white'
78

89
const GM_KEYS = {
910
black: {
@@ -20,6 +21,16 @@ const GM_KEYS = {
2021
valueKey: 'global-content-keyword-filter-value',
2122
},
2223
},
24+
white: {
25+
title: {
26+
statusKey: 'dyn-video-title-white-filter-status',
27+
valueKey: 'global-title-keyword-whitelist-filter-value',
28+
},
29+
content: {
30+
statusKey: 'dyn-content-white-filter-status',
31+
valueKey: 'global-content-keyword-whitelist-filter-value',
32+
},
33+
},
2334
}
2435

2536
// 动态信息提取
@@ -42,12 +53,18 @@ class DynamicFilterHeader implements IMainFilter {
4253
dynUploaderFilter = new DynUploaderFilter()
4354
dynVideoTitleFilter = new DynVideoTitleFilter()
4455
dynContentFilter = new DynContentFilter()
56+
// 白名单
57+
dynVideoTitleWhiteFilter = new DynVideoTitleWhiteFilter()
58+
dynContentWhiteFilter = new DynContentWhiteFilter()
4559

4660
init() {
4761
// 黑名单
4862
this.dynUploaderFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.uploader.valueKey, []))
4963
this.dynVideoTitleFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.title.valueKey, []))
5064
this.dynContentFilter.setParam(BiliCleanerStorage.get(GM_KEYS.black.content.valueKey, []))
65+
// 白名单
66+
this.dynVideoTitleWhiteFilter.setParam(BiliCleanerStorage.get(GM_KEYS.white.title.valueKey, []))
67+
this.dynContentWhiteFilter.setParam(BiliCleanerStorage.get(GM_KEYS.white.content.valueKey, []))
5168
}
5269

5370
async check(mode?: 'full' | 'incr') {
@@ -84,9 +101,13 @@ class DynamicFilterHeader implements IMainFilter {
84101
this.dynUploaderFilter.isEnable && blackPairs.push([this.dynUploaderFilter, selectorFns.uploader])
85102
this.dynVideoTitleFilter.isEnable && blackPairs.push([this.dynVideoTitleFilter, selectorFns.title])
86103
this.dynContentFilter.isEnable && blackPairs.push([this.dynContentFilter, selectorFns.content])
104+
// 构建白名单任务
105+
const whitePairs: SubFilterPair[] = []
106+
this.dynVideoTitleWhiteFilter.isEnable && whitePairs.push([this.dynVideoTitleWhiteFilter, selectorFns.title])
107+
this.dynContentWhiteFilter.isEnable && whitePairs.push([this.dynContentWhiteFilter, selectorFns.content])
87108

88109
// 检测
89-
const blackCnt = await coreCheck(dyns, true, 'style', blackPairs, [])
110+
const blackCnt = await coreCheck(dyns, true, 'style', blackPairs, whitePairs)
90111
const time = (performance.now() - timer).toFixed(1)
91112
debug(`DynamicFilterHeader hide ${blackCnt} in ${dyns.length} dyns, mode=${mode}, time=${time}`)
92113
}
@@ -104,23 +125,21 @@ class DynamicFilterHeader implements IMainFilter {
104125
// }
105126

106127
observe() {
107-
document.addEventListener('DOMContentLoaded', () => {
108-
let cnt = 0
109-
const id = setInterval(() => {
110-
const ele = document.querySelector('.right-entry .v-popover-wrap:nth-of-type(3)') as HTMLElement
111-
if (ele) {
112-
clearInterval(id)
113-
114-
debug('DynamicFilterHeader target appear')
115-
this.target = ele
128+
let cnt = 0
129+
const id = setInterval(() => {
130+
const ele = document.querySelector('.right-entry') as HTMLElement
131+
if (ele) {
132+
clearInterval(id)
133+
134+
debug('DynamicFilterHeader target appear')
135+
this.target = ele
136+
this.checkFull()
137+
new MutationObserver(() => {
116138
this.checkFull()
117-
new MutationObserver(() => {
118-
this.checkFull()
119-
}).observe(this.target, { childList: true, subtree: true })
120-
}
121-
++cnt > 10 && clearInterval(id)
122-
}, 1000)
123-
})
139+
}).observe(this.target, { childList: true, subtree: true })
140+
}
141+
++cnt > 10 && clearInterval(id)
142+
}, 1000)
124143
}
125144
}
126145

@@ -140,4 +159,10 @@ export const dynamicFilterHeaderEntry = async () => {
140159
if (BiliCleanerStorage.get(GM_KEYS.black.content.statusKey)) {
141160
mainFilter.dynContentFilter.enable()
142161
}
162+
if (BiliCleanerStorage.get(GM_KEYS.white.title.statusKey)) {
163+
mainFilter.dynVideoTitleWhiteFilter.enable()
164+
}
165+
if (BiliCleanerStorage.get(GM_KEYS.white.content.statusKey)) {
166+
mainFilter.dynContentWhiteFilter.enable()
167+
}
143168
}

src/modules/filters/variety/dynamic/pages/space.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export const dynamicFilterSpaceGroups: Group[] = [
286286
type: 'switch',
287287
id: GM_KEYS.black.content.statusKey,
288288
name: '启用 动态内容关键词过滤',
289-
description: ['不含动态内视频标题'],
289+
description: ['不覆盖动态内视频标题'],
290290
noStyle: true,
291291
enableFn: () => {
292292
mainFilter.dynContentFilter.enable()
@@ -385,7 +385,7 @@ export const dynamicFilterSpaceGroups: Group[] = [
385385
type: 'switch',
386386
id: GM_KEYS.white.content.statusKey,
387387
name: '启用 动态内容关键词白名单',
388-
description: ['不含动态内视频标题'],
388+
description: ['不覆盖动态内视频标题'],
389389
noStyle: true,
390390
enableFn: () => {
391391
mainFilter.dynContentWhiteFilter.enable()

0 commit comments

Comments
 (0)