Skip to content

Commit

Permalink
merge dev to main, v4.0.11 (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 authored Nov 22, 2024
2 parents e9eaaf0 + 32695f7 commit 576ce24
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 900 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 4.0.11

- 新增:播放页 展开视频合集第二行标题
- 更新:评论过滤 开关设定对全站通用
- 修复:评论过滤 排除自己的评论和@自己的评论

## 4.0.10

- 新增:评论区过滤 过滤@其他用户的无回复评论
Expand Down
44 changes: 16 additions & 28 deletions src/modules/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@ import {
} from '../../utils/pageType'
import { BiliCleanerStorage } from '../../utils/storage'
import {
commentFilterDynamicEntry,
commentFilterDynamicGroups,
commentFilterDynamicHandler,
} from './variety/comment/pages/dynamic'
commentFilterCommonEntry,
commentFilterCommonGroups,
commentFilterCommonHandler,
} from './variety/comment/pages/common'
import {
commentFilterSpaceEntry,
commentFilterSpaceGroups,
commentFilterSpaceHandler,
} from './variety/comment/pages/space'
import {
commentFilterVideoEntry,
commentFilterVideoGroups,
commentFilterVideoHandler,
} from './variety/comment/pages/video'
commentFilterLegacyEntry,
commentFilterLegacyGroups,
commentFilterLegacyHandler,
} from './variety/comment/pages/legacy'
import {
dynamicFilterDynamicEntry,
dynamicFilterDynamicGroups,
Expand Down Expand Up @@ -96,21 +91,15 @@ export const videoFilters: Filter[] = [
/** 评论过滤器 */
export const commentFilters: Filter[] = [
{
name: '视频页/番剧页 视频评论过滤',
groups: commentFilterVideoGroups,
entry: commentFilterVideoEntry,
checkFn: () => isPageVideo() || isPageBangumi() || isPagePlaylist(),
},
{
name: '动态页 动态评论过滤',
groups: commentFilterDynamicGroups,
entry: commentFilterDynamicEntry,
checkFn: () => isPageDynamic(),
name: '视频页/番剧页/动态页 视频评论过滤',
groups: commentFilterCommonGroups,
entry: commentFilterCommonEntry,
checkFn: () => isPageVideo() || isPageBangumi() || isPagePlaylist() || isPageDynamic(),
},
{
name: '空间页 动态评论过滤',
groups: commentFilterSpaceGroups,
entry: commentFilterSpaceEntry,
groups: commentFilterLegacyGroups,
entry: commentFilterLegacyEntry,
checkFn: () => isPageSpace(),
},
]
Expand Down Expand Up @@ -181,7 +170,6 @@ export const filterContextMenuHandlers = [
videoFilterPopularHandler,
videoFilterHomepageHandler,
dynamicFilterDynamicHandler,
commentFilterVideoHandler,
commentFilterDynamicHandler,
commentFilterSpaceHandler,
commentFilterCommonHandler,
commentFilterLegacyHandler,
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../../../types/filter'
import fetchHook from '../../../../../utils/fetch'
import { debugFilter as debug, error } from '../../../../../utils/logger'
import { isPageBangumi, isPagePlaylist, isPageVideo } from '../../../../../utils/pageType'
import { isPageBangumi, isPageDynamic, isPagePlaylist, isPageVideo } from '../../../../../utils/pageType'
import ShadowInstance from '../../../../../utils/shadow'
import { BiliCleanerStorage } from '../../../../../utils/storage'
import { orderedUniq, showEle } from '../../../../../utils/tool'
Expand All @@ -26,7 +26,13 @@ import {
CommentLevelFilter,
CommentUsernameFilter,
} from '../subFilters/black'
import { CommentIsLinkFilter, CommentIsNoteFilter, CommentIsPinFilter, CommentIsUpFilter } from '../subFilters/white'
import {
CommentIsLinkFilter,
CommentIsMeFilter,
CommentIsNoteFilter,
CommentIsPinFilter,
CommentIsUpFilter,
} from '../subFilters/white'

const GM_KEYS = {
black: {
Expand Down Expand Up @@ -145,6 +151,20 @@ const selectorFns = {
}
return false
},
// 自己发布 or @自己 的评论
isMe: (comment: HTMLElement): SelectorResult => {
const me = (comment as any).__user?.uname
if (!me) {
return false
}
if (
(comment as any).__data?.member?.uname === me ||
(comment as any).__data?.content?.message?.includes(`@${me}`)
) {
return true
}
return false
},
},
sub: {
username: (comment: HTMLElement): SelectorResult => {
Expand All @@ -165,6 +185,14 @@ const selectorFns = {
.replace('@', '')
.trim()
},
callUserNoReply: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.content?.message
?.trim()
?.replace(/^回复\s?@[^@\s]+\s?:/, '')
?.match(/@[^@\s]+/)?.[0]
.replace('@', '')
.trim()
},
callUserOnly: (comment: HTMLElement): SelectorResult => {
return (
(comment as any).__data?.content?.message
Expand All @@ -174,6 +202,15 @@ const selectorFns = {
.trim() === ''
)
},
callUserOnlyNoReply: (comment: HTMLElement): SelectorResult => {
return (
(comment as any).__data?.content?.message
?.trim()
?.replace(/^回复\s?@[^@\s]+\s?:/, '')
?.replace(/@[^@\s]+/g, ' ')
.trim() === ''
)
},
level: (comment: HTMLElement): SelectorResult => {
return (comment as any).__data?.member?.level_info?.current_level
},
Expand All @@ -193,14 +230,31 @@ const selectorFns = {
}
return false
},
// 自己发布 or @自己 的评论
isMe: (comment: HTMLElement): SelectorResult => {
const me = (comment as any).__user?.uname
if (!me) {
return false
}
if (
(comment as any).__data?.member?.uname === me ||
(comment as any).__data?.content?.message
?.trim()
?.replace(/^回复\s?@[^@\s]+\s?:/, '')
.includes(`@${me}`)
) {
return true
}
return false
},
},
}

// 一二级评论是否检测
let isRootWhite = false
let isSubWhite = false

class CommentFilterVideo implements IMainFilter {
class CommentFilterCommon implements IMainFilter {
target: HTMLElement | undefined

// 黑名单
Expand All @@ -218,6 +272,7 @@ class CommentFilterVideo implements IMainFilter {
commentIsPinFilter = new CommentIsPinFilter()
commentIsNoteFilter = new CommentIsNoteFilter()
commentIsLinkFilter = new CommentIsLinkFilter()
commentIsMeFilter = new CommentIsMeFilter()

init() {
// 黑名单
Expand Down Expand Up @@ -271,7 +326,7 @@ class CommentFilterVideo implements IMainFilter {
rootComments.forEach((v) => {
debug(
[
`CommentFilterVideo rootComments`,
`CommentFilterCommon rootComments`,
`username: ${selectorFns.root.username(v)}`,
`content: ${selectorFns.root.content(v)}`,
`callUser: ${selectorFns.root.callUser(v)}`,
Expand All @@ -283,6 +338,7 @@ class CommentFilterVideo implements IMainFilter {
`isPin: ${selectorFns.root.isPin(v)}`,
`isNote: ${selectorFns.root.isNote(v)}`,
`isLink: ${selectorFns.root.isLink(v)}`,
`isMe: ${selectorFns.root.isMe(v)}`,
].join('\n'),
)
})
Expand Down Expand Up @@ -312,11 +368,12 @@ class CommentFilterVideo implements IMainFilter {
this.commentIsPinFilter.isEnable && whitePairs.push([this.commentIsPinFilter, selectorFns.root.isPin])
this.commentIsNoteFilter.isEnable && whitePairs.push([this.commentIsNoteFilter, selectorFns.root.isNote])
this.commentIsLinkFilter.isEnable && whitePairs.push([this.commentIsLinkFilter, selectorFns.root.isLink])
this.commentIsMeFilter.isEnable && whitePairs.push([this.commentIsMeFilter, selectorFns.root.isMe])

const rootBlackCnt = await coreCheck(rootComments, true, blackPairs, whitePairs)
const time = (performance.now() - timer).toFixed(1)
debug(
`CommentFilterVideo hide ${rootBlackCnt} in ${rootComments.length} root comments, mode=${mode}, time=${time}`,
`CommentFilterCommon hide ${rootBlackCnt} in ${rootComments.length} root comments, mode=${mode}, time=${time}`,
)
}

Expand All @@ -336,7 +393,9 @@ class CommentFilterVideo implements IMainFilter {
this.commentBotFilter.isEnable ||
this.commentCallBotFilter.isEnable ||
this.commentCallUserFilter.isEnable ||
this.commentCallUserOnlyFilter.isEnable
this.commentCallUserNoReplyFilter.isEnable ||
this.commentCallUserOnlyFilter.isEnable ||
this.commentCallUserOnlyNoReplyFilter.isEnable
)
) {
revertAll = true
Expand All @@ -359,14 +418,17 @@ class CommentFilterVideo implements IMainFilter {
subComments.forEach((v) => {
debug(
[
`CommentFilterVideo subComments`,
`CommentFilterCommon subComments`,
`username: ${selectorFns.sub.username(v)}`,
`content: ${selectorFns.sub.content(v)}`,
`callUser: ${selectorFns.sub.callUser(v)}`,
`callUserNoReply: ${selectorFns.sub.callUserNoReply(v)}`,
`callUserOnly: ${selectorFns.sub.callUserOnly(v)}`,
`callUserOnlyNoReply: ${selectorFns.sub.callUserOnlyNoReply(v)}`,
`level: ${selectorFns.sub.level(v)}`,
`isUp: ${selectorFns.sub.isUp(v)}`,
`isLink: ${selectorFns.sub.isLink(v)}`,
`isMe: ${selectorFns.sub.isMe(v)}`,
].join('\n'),
)
})
Expand All @@ -384,30 +446,35 @@ class CommentFilterVideo implements IMainFilter {
this.commentBotFilter.isEnable && blackPairs.push([this.commentBotFilter, selectorFns.sub.username])
this.commentCallBotFilter.isEnable && blackPairs.push([this.commentCallBotFilter, selectorFns.sub.callUser])
this.commentCallUserFilter.isEnable && blackPairs.push([this.commentCallUserFilter, selectorFns.sub.callUser])
this.commentCallUserNoReplyFilter.isEnable &&
blackPairs.push([this.commentCallUserNoReplyFilter, selectorFns.sub.callUserNoReply])
this.commentCallUserOnlyFilter.isEnable &&
blackPairs.push([this.commentCallUserOnlyFilter, selectorFns.sub.callUserOnly])
this.commentCallUserOnlyNoReplyFilter.isEnable &&
blackPairs.push([this.commentCallUserOnlyNoReplyFilter, selectorFns.sub.callUserOnlyNoReply])

const whitePairs: SubFilterPair[] = []
this.commentIsUpFilter.isEnable && whitePairs.push([this.commentIsUpFilter, selectorFns.sub.isUp])
this.commentIsLinkFilter.isEnable && whitePairs.push([this.commentIsLinkFilter, selectorFns.sub.isLink])
this.commentIsMeFilter.isEnable && whitePairs.push([this.commentIsMeFilter, selectorFns.sub.isMe])

const subBlackCnt = await coreCheck(subComments, false, blackPairs, whitePairs)
const time = (performance.now() - timer).toFixed(1)
debug(
`CommentFilterVideo hide ${subBlackCnt} in ${subComments.length} sub comments, mode=${mode}, time=${time}`,
`CommentFilterCommon hide ${subBlackCnt} in ${subComments.length} sub comments, mode=${mode}, time=${time}`,
)
}

check(mode?: 'full' | 'incr') {
this.checkRoot(mode)
.then()
.catch((err) => {
error(`CommentFilterVideo checkRoot mode=${mode} error`, err)
error(`CommentFilterCommon checkRoot mode=${mode} error`, err)
})
this.checkSub(mode)
.then()
.catch((err) => {
error(`CommentFilterVideo checkSub mode=${mode} error`, err)
error(`CommentFilterCommon checkSub mode=${mode} error`, err)
})
}

Expand Down Expand Up @@ -442,14 +509,15 @@ class CommentFilterVideo implements IMainFilter {

//==================================================================================================

const mainFilter = new CommentFilterVideo()
const mainFilter = new CommentFilterCommon()

export const commentFilterVideoEntry = async () => {
export const commentFilterCommonEntry = async () => {
mainFilter.init()
mainFilter.commentIsMeFilter.enable()
mainFilter.observe()
}

export const commentFilterVideoGroups: Group[] = [
export const commentFilterCommonGroups: Group[] = [
{
name: '评论用户过滤',
items: [
Expand Down Expand Up @@ -772,8 +840,8 @@ export const commentFilterVideoGroups: Group[] = [
]

// 右键菜单handler
export const commentFilterVideoHandler: ContextMenuTargetHandler = (target: HTMLElement): FilterContextMenu[] => {
if (!(isPageVideo() || isPagePlaylist() || isPageBangumi())) {
export const commentFilterCommonHandler: ContextMenuTargetHandler = (target: HTMLElement): FilterContextMenu[] => {
if (!(isPageVideo() || isPagePlaylist() || isPageBangumi() || isPageDynamic())) {
return []
}

Expand All @@ -795,7 +863,7 @@ export const commentFilterVideoHandler: ContextMenuTargetHandler = (target: HTML
arr.unshift(username)
BiliCleanerStorage.set<string[]>(GM_KEYS.black.username.valueKey, orderedUniq(arr))
} catch (err) {
error(`commentFilterVideoHandler add username ${username} failed`, err)
error(`commentFilterCommonHandler add username ${username} failed`, err)
}
},
})
Expand Down
Loading

0 comments on commit 576ce24

Please sign in to comment.