11import { coreCheck } from '@/modules/filters/core/core'
22import settings from '@/settings'
3+ import emojiRegex from 'emoji-regex-xs'
34import { Group } from '@/types/collection'
45import { ContextMenuTargetHandler , FilterContextMenu , IMainFilter , SelectorResult , SubFilterPair } from '@/types/filter'
56import { debugFilter as debug , error } from '@/utils/logger'
@@ -17,6 +18,7 @@ import {
1718 CommentCallUserOnlyFilter ,
1819 CommentCallUserOnlyNoReplyFilter ,
1920 CommentContentFilter ,
21+ CommentEmojiOnlyFilter ,
2022 CommentLevelFilter ,
2123 CommentNoFaceFilter ,
2224 CommentUsernameFilter ,
@@ -72,6 +74,9 @@ const GM_KEYS = {
7274 isAD : {
7375 statusKey : 'video-comment-ad-filter-status' ,
7476 } ,
77+ emojiOnly : {
78+ statusKey : 'video-comment-emoji-only-filter-status' ,
79+ } ,
7580 } ,
7681 white : {
7782 root : {
@@ -103,13 +108,17 @@ const GM_KEYS = {
103108// https://b23.tv/av1705573085
104109// https://b23.tv/av1350214762
105110// https://b23.tv/av113195607985861
111+ const emojiPattern = emojiRegex ( )
106112const selectorFns = {
107113 root : {
108114 username : ( comment : HTMLElement ) : SelectorResult => {
109115 return ( comment as any ) . __data ?. member ?. uname ?. trim ( )
110116 } ,
111117 content : ( comment : HTMLElement ) : SelectorResult => {
112- return ( comment as any ) . __data ?. content ?. message ?. replace ( / @ [ ^ @ \s ] + / g, ' ' ) . trim ( )
118+ return ( comment as any ) . __data ?. content ?. message
119+ ?. replace ( / @ [ ^ @ \s ] + / g, ' ' )
120+ ?. replace ( / ( \[ [ ^ [ \] ] + \] ) + / g, ' ' )
121+ . trim ( )
113122 } ,
114123 noface : ( comment : HTMLElement ) : SelectorResult => {
115124 return (
@@ -145,6 +154,15 @@ const selectorFns = {
145154 level : ( comment : HTMLElement ) : SelectorResult => {
146155 return ( comment as any ) . __data ?. member ?. level_info ?. current_level
147156 } ,
157+ emojiOnly : ( comment : HTMLElement ) : SelectorResult => {
158+ return (
159+ ( comment as any ) . __data ?. content ?. message
160+ ?. replace ( / @ [ ^ @ \s ] + / g, ' ' )
161+ ?. replace ( / ( \[ [ ^ [ \] ] + \] ) + / g, ' ' )
162+ ?. replace ( emojiPattern , ' ' )
163+ . trim ( ) === ''
164+ )
165+ } ,
148166 isUp : ( comment : HTMLElement ) : SelectorResult => {
149167 const mid = ( comment as any ) . __data ?. mid
150168 const upMid = ( comment as any ) . __upMid
@@ -191,6 +209,7 @@ const selectorFns = {
191209 ?. trim ( )
192210 ?. replace ( / ^ 回 复 \s ? @ [ ^ @ \s ] + \s ? : / , '' )
193211 ?. replace ( / @ [ ^ @ \s ] + / g, ' ' )
212+ ?. replace ( / ( \[ [ ^ [ \] ] + \] ) + / g, ' ' )
194213 . trim ( )
195214 } ,
196215 noface : ( comment : HTMLElement ) : SelectorResult => {
@@ -239,6 +258,16 @@ const selectorFns = {
239258 level : ( comment : HTMLElement ) : SelectorResult => {
240259 return ( comment as any ) . __data ?. member ?. level_info ?. current_level
241260 } ,
261+ emojiOnly : ( comment : HTMLElement ) : SelectorResult => {
262+ return (
263+ ( comment as any ) . __data ?. content ?. message
264+ ?. replace ( / ^ 回 复 \s ? @ [ ^ @ \s ] + \s ? : / , '' )
265+ ?. replace ( / @ [ ^ @ \s ] + / g, ' ' )
266+ ?. replace ( / ( \[ [ ^ [ \] ] + \] ) + / g, ' ' )
267+ ?. replace ( emojiPattern , ' ' )
268+ . trim ( ) === ''
269+ )
270+ } ,
242271 isUp : ( comment : HTMLElement ) : SelectorResult => {
243272 const mid = ( comment as any ) . __data ?. mid
244273 const upMid = ( comment as any ) . __upMid
@@ -295,6 +324,7 @@ class CommentFilterCommon implements IMainFilter {
295324 commentCallUserNoReplyFilter = new CommentCallUserNoReplyFilter ( )
296325 commentCallUserOnlyFilter = new CommentCallUserOnlyFilter ( )
297326 commentCallUserOnlyNoReplyFilter = new CommentCallUserOnlyNoReplyFilter ( )
327+ commentEmojiOnlyFilter = new CommentEmojiOnlyFilter ( )
298328 // 白名单
299329 commentIsUpFilter = new CommentIsUpFilter ( )
300330 commentIsPinFilter = new CommentIsPinFilter ( )
@@ -333,7 +363,8 @@ class CommentFilterCommon implements IMainFilter {
333363 this . commentCallUserFilter . isEnable ||
334364 this . commentCallUserNoReplyFilter . isEnable ||
335365 this . commentCallUserOnlyFilter . isEnable ||
336- this . commentCallUserOnlyNoReplyFilter . isEnable
366+ this . commentCallUserOnlyNoReplyFilter . isEnable ||
367+ this . commentEmojiOnlyFilter . isEnable
337368 )
338369 ) {
339370 revertAll = true
@@ -370,6 +401,7 @@ class CommentFilterCommon implements IMainFilter {
370401 `isNote: ${ selectorFns . root . isNote ( v ) } ` ,
371402 `isLink: ${ selectorFns . root . isLink ( v ) } ` ,
372403 `isMe: ${ selectorFns . root . isMe ( v ) } ` ,
404+ `emojiOnly: ${ selectorFns . root . emojiOnly ( v ) } ` ,
373405 ] . join ( '\n' ) ,
374406 )
375407 } )
@@ -396,6 +428,8 @@ class CommentFilterCommon implements IMainFilter {
396428 blackPairs . push ( [ this . commentCallUserOnlyFilter , selectorFns . root . callUserOnly ] )
397429 this . commentCallUserOnlyNoReplyFilter . isEnable &&
398430 blackPairs . push ( [ this . commentCallUserOnlyNoReplyFilter , selectorFns . root . callUserOnlyNoReply ] )
431+ this . commentEmojiOnlyFilter . isEnable &&
432+ blackPairs . push ( [ this . commentEmojiOnlyFilter , selectorFns . root . emojiOnly ] )
399433
400434 const whitePairs : SubFilterPair [ ] = [ ]
401435 this . commentIsUpFilter . isEnable && whitePairs . push ( [ this . commentIsUpFilter , selectorFns . root . isUp ] )
@@ -435,7 +469,8 @@ class CommentFilterCommon implements IMainFilter {
435469 this . commentCallUserFilter . isEnable ||
436470 this . commentCallUserNoReplyFilter . isEnable ||
437471 this . commentCallUserOnlyFilter . isEnable ||
438- this . commentCallUserOnlyNoReplyFilter . isEnable
472+ this . commentCallUserOnlyNoReplyFilter . isEnable ||
473+ this . commentEmojiOnlyFilter . isEnable
439474 )
440475 ) {
441476 revertAll = true
@@ -470,6 +505,7 @@ class CommentFilterCommon implements IMainFilter {
470505 `isUp: ${ selectorFns . sub . isUp ( v ) } ` ,
471506 `isLink: ${ selectorFns . sub . isLink ( v ) } ` ,
472507 `isMe: ${ selectorFns . sub . isMe ( v ) } ` ,
508+ `emojiOnly: ${ selectorFns . sub . emojiOnly ( v ) } ` ,
473509 ] . join ( '\n' ) ,
474510 )
475511 } )
@@ -496,6 +532,8 @@ class CommentFilterCommon implements IMainFilter {
496532 blackPairs . push ( [ this . commentCallUserOnlyFilter , selectorFns . sub . callUserOnly ] )
497533 this . commentCallUserOnlyNoReplyFilter . isEnable &&
498534 blackPairs . push ( [ this . commentCallUserOnlyNoReplyFilter , selectorFns . sub . callUserOnlyNoReply ] )
535+ this . commentEmojiOnlyFilter . isEnable &&
536+ blackPairs . push ( [ this . commentEmojiOnlyFilter , selectorFns . sub . emojiOnly ] )
499537
500538 const whitePairs : SubFilterPair [ ] = [ ]
501539 this . commentIsUpFilter . isEnable && whitePairs . push ( [ this . commentIsUpFilter , selectorFns . sub . isUp ] )
@@ -693,7 +731,7 @@ export const commentFilterCommonGroups: Group[] = [
693731 {
694732 type : 'switch' ,
695733 id : GM_KEYS . black . isAD . statusKey ,
696- name : '过滤 带货评论 (实验功能) ' ,
734+ name : '过滤 带货评论' ,
697735 noStyle : true ,
698736 enableFn : ( ) => {
699737 mainFilter . commentAdFilter . enable ( )
@@ -704,6 +742,20 @@ export const commentFilterCommonGroups: Group[] = [
704742 mainFilter . check ( 'full' )
705743 } ,
706744 } ,
745+ {
746+ type : 'switch' ,
747+ id : GM_KEYS . black . emojiOnly . statusKey ,
748+ name : '过滤 只有表情的评论' ,
749+ noStyle : true ,
750+ enableFn : ( ) => {
751+ mainFilter . commentEmojiOnlyFilter . enable ( )
752+ mainFilter . check ( 'full' )
753+ } ,
754+ disableFn : ( ) => {
755+ mainFilter . commentEmojiOnlyFilter . disable ( )
756+ mainFilter . check ( 'full' )
757+ } ,
758+ } ,
707759 {
708760 type : 'switch' ,
709761 id : GM_KEYS . black . noface . statusKey ,
0 commit comments