Skip to content

Commit

Permalink
feat: comment filter hide callUserOnly #139
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Sep 27, 2024
1 parent 1caedef commit 325a7af
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.11.4

- 更新:播放页视频合集相关净化功能,适配网页变化
- 新增:评论区过滤 过滤只含@其他用户的评论

## 3.11.3

Expand Down
43 changes: 38 additions & 5 deletions src/filters/comment/dyn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CommentBotFilter,
CommentCallBotFilter,
CommentCallUserFilter,
CommentCallUserOnlyFilter,
CommentContentFilter,
CommentLevelFilter,
CommentUsernameFilter,
Expand Down Expand Up @@ -43,6 +44,9 @@ const GM_KEYS = {
callUser: {
statusKey: 'dynamic-comment-call-user-filter-status',
},
callUserOnly: {
statusKey: 'dynamic-comment-call-user-only-filter-status',
},
isAD: {
statusKey: 'dynamic-comment-ad-filter-status',
},
Expand Down Expand Up @@ -81,6 +85,9 @@ const selectorFns = {
callUser: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.members[0]?.uname
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message?.replace(/@[^@ ]+/g, '').trim() === ''
},
level: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.member?.level_info?.current_level
},
Expand Down Expand Up @@ -127,6 +134,9 @@ const selectorFns = {
.replace('@', '')
.trim()
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message?.replace(/@[^@ ]+/g, '').trim() === ''
},
level: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.member?.level_info?.current_level
},
Expand Down Expand Up @@ -221,6 +231,8 @@ if (isPageDynamic()) {
const commentCallUserFilter = new CommentCallUserFilter()
commentCallUserFilter.addParam(`/./`)

const commentCallUserOnlyFilter = new CommentCallUserOnlyFilter()

// 初始化白名单
const commentIsUpFilter = new CommentIsUpFilter()
const commentIsPinFilter = new CommentIsPinFilter()
Expand All @@ -236,7 +248,8 @@ if (isPageDynamic()) {
commentLevelFilter.isEnable ||
commentBotFilter.isEnable ||
commentCallBotFilter.isEnable ||
commentCallUserFilter.isEnable
commentCallUserFilter.isEnable ||
commentCallUserOnlyFilter.isEnable
)
) {
return
Expand All @@ -262,6 +275,7 @@ if (isPageDynamic()) {
// `username: ${selectorFns.root.username(v)}`,
// `content: ${selectorFns.root.content(v)}`,
// `callUser: ${selectorFns.root.callUser(v)}`,
// `callUserOnly: ${selectorFns.root.callUserOnly(v)}`,
// `level: ${selectorFns.root.level(v)}`,
// `isUp: ${selectorFns.root.isUp(v)}`,
// `isPin: ${selectorFns.root.isPin(v)}`,
Expand All @@ -283,6 +297,8 @@ if (isPageDynamic()) {
commentBotFilter.isEnable && blackPairs.push([commentBotFilter, selectorFns.root.username])
commentCallBotFilter.isEnable && blackPairs.push([commentCallBotFilter, selectorFns.root.callUser])
commentCallUserFilter.isEnable && blackPairs.push([commentCallUserFilter, selectorFns.root.callUser])
commentCallUserOnlyFilter.isEnable &&
blackPairs.push([commentCallUserOnlyFilter, selectorFns.root.callUserOnly])

const whitePairs: SubFilterPair[] = []
commentIsUpFilter.isEnable && whitePairs.push([commentIsUpFilter, selectorFns.root.isUp])
Expand All @@ -303,7 +319,8 @@ if (isPageDynamic()) {
commentLevelFilter.isEnable ||
commentBotFilter.isEnable ||
commentCallBotFilter.isEnable ||
commentCallUserFilter.isEnable
commentCallUserFilter.isEnable ||
commentCallUserOnlyFilter.isEnable
)
) {
return
Expand All @@ -329,6 +346,7 @@ if (isPageDynamic()) {
// `username: ${selectorFns.sub.username(v)}`,
// `content: ${selectorFns.sub.content(v)}`,
// `callUser: ${selectorFns.sub.callUser(v)}`,
// `callUserOnly: ${selectorFns.sub.callUserOnly(v)}`,
// `level: ${selectorFns.sub.level(v)}`,
// `isUp: ${selectorFns.sub.isUp(v)}`,
// `isLink: ${selectorFns.sub.isLink(v)}`,
Expand All @@ -348,6 +366,7 @@ if (isPageDynamic()) {
commentBotFilter.isEnable && blackPairs.push([commentBotFilter, selectorFns.sub.username])
commentCallBotFilter.isEnable && blackPairs.push([commentCallBotFilter, selectorFns.sub.callUser])
commentCallUserFilter.isEnable && blackPairs.push([commentCallUserFilter, selectorFns.sub.callUser])
commentCallUserOnlyFilter.isEnable && blackPairs.push([commentCallUserOnlyFilter, selectorFns.sub.callUserOnly])

const whitePairs: SubFilterPair[] = []
commentIsUpFilter.isEnable && whitePairs.push([commentIsUpFilter, selectorFns.sub.isUp])
Expand All @@ -365,7 +384,8 @@ if (isPageDynamic()) {
commentLevelFilter.isEnable ||
commentBotFilter.isEnable ||
commentCallBotFilter.isEnable ||
commentCallUserFilter.isEnable
commentCallUserFilter.isEnable ||
commentCallUserOnlyFilter.isEnable
) {
checkRoot(fullSite).then().catch()
checkSub(fullSite).then().catch()
Expand Down Expand Up @@ -565,10 +585,23 @@ if (isPageDynamic()) {
checkAll(true)
},
}),
// 过滤 @其他用户的评论
// 过滤 只含 @其他用户 的评论
new CheckboxItem({
itemID: GM_KEYS.black.callUserOnly.statusKey,
description: '过滤 只含 @其他用户 的评论',
enableFunc: () => {
commentCallUserOnlyFilter.enable()
checkAll(true)
},
disableFunc: () => {
commentCallUserOnlyFilter.disable()
checkAll(true)
},
}),
// 过滤 包含 @其他用户 的评论
new CheckboxItem({
itemID: GM_KEYS.black.callUser.statusKey,
description: '过滤 @其他用户的评论',
description: '过滤 包含 @其他用户 的评论',
enableFunc: () => {
commentCallUserFilter.enable()
checkAll(true)
Expand Down
58 changes: 48 additions & 10 deletions src/filters/comment/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CommentBotFilter,
CommentCallBotFilter,
CommentCallUserFilter,
CommentCallUserOnlyFilter,
CommentContentFilter,
CommentLevelFilter,
CommentUsernameFilter,
Expand Down Expand Up @@ -42,8 +43,11 @@ const GM_KEYS = {
callUser: {
statusKey: 'dynamic-comment-call-user-filter-status',
},
callUserOnly: {
statusKey: 'dynamic-comment-call-user-only-filter-status',
},
isAD: {
statusKey: 'video-comment-ad-filter-status',
statusKey: 'dynamic-comment-ad-filter-status',
},
},
white: {
Expand All @@ -70,12 +74,6 @@ const GM_KEYS = {

// 一二级评论信息提取
const selectorFns = {
// 测试视频:
// https://b23.tv/av810872
// https://b23.tv/av1855797296
// https://b23.tv/av1706101190
// https://b23.tv/av1705573085
// https://b23.tv/av1350214762
root: {
username: (comment: HTMLElement): SelectorResult => {
return comment.querySelector('.root-reply-container .user-name')?.textContent?.trim()
Expand All @@ -93,6 +91,15 @@ const selectorFns = {
?.textContent?.replace('@', '')
.trim()
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (
comment
.querySelector('.root-reply-container .reply-content')
?.textContent?.trim()
.replace(/@[^@ ]+/g, '')
.trim() === ''
)
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.root-reply-container .user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
Expand Down Expand Up @@ -133,6 +140,15 @@ const selectorFns = {
.replace('@', '')
.trim()
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (
comment
.querySelector('.reply-content')
?.textContent?.trim()
.replace(/@[^@ ]+/g, '')
.trim() === ''
)
},
level: (comment: HTMLElement): SelectorResult => {
const c = comment.querySelector('.sub-user-level')?.className
const lv = c?.match(/level-([1-6])/)?.[1] // 忽略level-hardcore
Expand Down Expand Up @@ -219,6 +235,8 @@ if (isPageSpace()) {
const commentCallUserFilter = new CommentCallUserFilter()
commentCallUserFilter.addParam(`/./`)

const commentCallUserOnlyFilter = new CommentCallUserOnlyFilter()

// 初始化白名单
const commentIsUpFilter = new CommentIsUpFilter()
const commentIsPinFilter = new CommentIsPinFilter()
Expand Down Expand Up @@ -255,6 +273,7 @@ if (isPageSpace()) {
// `username: ${selectorFns.root.username(v)}`,
// `content: ${selectorFns.root.content(v)}`,
// `callUser: ${selectorFns.root.callUser(v)}`,
// `callUserOnly: ${selectorFns.root.callUserOnly(v)}`,
// `level: ${selectorFns.root.level(v)}`,
// `isUp: ${selectorFns.root.isUp(v)}`,
// `isPin: ${selectorFns.root.isPin(v)}`,
Expand All @@ -270,6 +289,7 @@ if (isPageSpace()) {
// `username: ${selectorFns.sub.username(v)}`,
// `content: ${selectorFns.sub.content(v)}`,
// `callUser: ${selectorFns.sub.callUser(v)}`,
// `callUserOnly: ${selectorFns.sub.callUserOnly(v)}`,
// `level: ${selectorFns.sub.level(v)}`,
// `isUp: ${selectorFns.sub.isUp(v)}`,
// `isLink: ${selectorFns.sub.isLink(v)}`,
Expand All @@ -286,6 +306,8 @@ if (isPageSpace()) {
commentBotFilter.isEnable && blackPairs.push([commentBotFilter, selectorFns.root.username])
commentCallBotFilter.isEnable && blackPairs.push([commentCallBotFilter, selectorFns.root.callUser])
commentCallUserFilter.isEnable && blackPairs.push([commentCallUserFilter, selectorFns.root.callUser])
commentCallUserOnlyFilter.isEnable &&
blackPairs.push([commentCallUserOnlyFilter, selectorFns.root.callUserOnly])

const whitePairs: SubFilterPair[] = []
commentIsUpFilter.isEnable && whitePairs.push([commentIsUpFilter, selectorFns.root.isUp])
Expand All @@ -305,6 +327,8 @@ if (isPageSpace()) {
commentBotFilter.isEnable && blackPairs.push([commentBotFilter, selectorFns.sub.username])
commentCallBotFilter.isEnable && blackPairs.push([commentCallBotFilter, selectorFns.sub.callUser])
commentCallUserFilter.isEnable && blackPairs.push([commentCallUserFilter, selectorFns.sub.callUser])
commentCallUserOnlyFilter.isEnable &&
blackPairs.push([commentCallUserOnlyFilter, selectorFns.sub.callUserOnly])

const whitePairs: SubFilterPair[] = []
commentIsUpFilter.isEnable && whitePairs.push([commentIsUpFilter, selectorFns.sub.isUp])
Expand All @@ -327,7 +351,8 @@ if (isPageSpace()) {
commentLevelFilter.isEnable ||
commentBotFilter.isEnable ||
commentCallBotFilter.isEnable ||
commentCallUserFilter.isEnable
commentCallUserFilter.isEnable ||
commentCallUserOnlyFilter.isEnable
) {
checkCommentList(fullSite).then().catch()
}
Expand Down Expand Up @@ -524,10 +549,23 @@ if (isPageSpace()) {
check(true)
},
}),
// 过滤 @其他用户的评论
// 过滤 只含 @其他用户 的评论
new CheckboxItem({
itemID: GM_KEYS.black.callUserOnly.statusKey,
description: '过滤 只含 @其他用户 的评论',
enableFunc: () => {
commentCallUserOnlyFilter.enable()
check(true)
},
disableFunc: () => {
commentCallUserOnlyFilter.disable()
check(true)
},
}),
// 过滤 包含 @其他用户 的评论
new CheckboxItem({
itemID: GM_KEYS.black.callUser.statusKey,
description: '过滤 @其他用户的评论',
description: '过滤 包含 @其他用户 的评论',
enableFunc: () => {
commentCallUserFilter.enable()
check(true)
Expand Down
3 changes: 3 additions & 0 deletions src/filters/comment/subFilters/black.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BooleanFilter } from '../../core/subFilters/booleanFilter'
import { KeywordFilter } from '../../core/subFilters/keywordFilter'
import { NumberMinFilter } from '../../core/subFilters/numberMinFilter'
import { StringFilter } from '../../core/subFilters/stringFilter'
Expand All @@ -13,3 +14,5 @@ export class CommentBotFilter extends StringFilter {}
export class CommentCallBotFilter extends StringFilter {}

export class CommentCallUserFilter extends KeywordFilter {}

export class CommentCallUserOnlyFilter extends BooleanFilter {}
Loading

0 comments on commit 325a7af

Please sign in to comment.