forked from inotia00/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 7
/
CommentsFilter.java
111 lines (91 loc) 路 4.14 KB
/
CommentsFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package app.revanced.integrations.youtube.patches.components;
import androidx.annotation.Nullable;
import java.util.regex.Pattern;
import app.revanced.integrations.youtube.settings.SettingsEnum;
import app.revanced.integrations.youtube.utils.StringTrieSearch;
/**
* @noinspection rawtypes
*/
@SuppressWarnings("unused")
final class CommentsFilter extends Filter {
private static final String COMMENT_COMPOSER_PATH = "comment_composer";
private static final String COMMENT_ENTRY_POINT_TEASER_PATH = "comments_entry_point_teaser";
private static final Pattern COMMENT_PREVIEW_TEXT_PATTERN = Pattern.compile("comments_entry_point_teaser.+ContainerType");
private static final String VIDEO_METADATA_CAROUSEL_PATH = "video_metadata_carousel.eml";
private final StringFilterGroup commentsPreviewDots;
private final StringFilterGroup createShorts;
private final StringFilterGroup emojiPicker;
private final StringFilterGroup previewCommentText;
private final StringFilterGroup thanks;
private final StringTrieSearch exceptions = new StringTrieSearch();
public CommentsFilter() {
exceptions.addPatterns("macro_markers_list_item");
final StringFilterGroup channelGuidelines = new StringFilterGroup(
SettingsEnum.HIDE_CHANNEL_GUIDELINES,
"channel_guidelines_entry_banner",
"community_guidelines",
"sponsorships_comments_upsell"
);
final StringFilterGroup comments = new StringFilterGroup(
SettingsEnum.HIDE_COMMENTS_SECTION,
VIDEO_METADATA_CAROUSEL_PATH,
"comments_"
);
commentsPreviewDots = new StringFilterGroup(
SettingsEnum.HIDE_PREVIEW_COMMENT_OLD_METHOD,
"|ContainerType|ContainerType|ContainerType|"
);
createShorts = new StringFilterGroup(
SettingsEnum.HIDE_CREATE_SHORTS_BUTTON,
"composer_short_creation_button"
);
emojiPicker = new StringFilterGroup(
SettingsEnum.HIDE_EMOJI_PICKER,
"|CellType|ContainerType|ContainerType|ContainerType|ContainerType|ContainerType|"
);
final StringFilterGroup membersBanner = new StringFilterGroup(
SettingsEnum.HIDE_COMMENTS_BY_MEMBERS,
"sponsorships_comments"
);
final StringFilterGroup previewComment = new StringFilterGroup(
SettingsEnum.HIDE_PREVIEW_COMMENT_OLD_METHOD,
"|carousel_item",
"|carousel_listener",
COMMENT_ENTRY_POINT_TEASER_PATH,
"comments_entry_point_simplebox"
);
previewCommentText = new StringFilterGroup(
SettingsEnum.HIDE_PREVIEW_COMMENT_NEW_METHOD,
COMMENT_ENTRY_POINT_TEASER_PATH
);
thanks = new StringFilterGroup(
SettingsEnum.HIDE_COMMENTS_THANKS_BUTTON,
"|super_thanks_button.eml"
);
identifierFilterGroupList.addAll(channelGuidelines);
pathFilterGroupList.addAll(
comments,
commentsPreviewDots,
createShorts,
emojiPicker,
membersBanner,
previewComment,
previewCommentText,
thanks
);
}
@Override
boolean isFiltered(String path, @Nullable String identifier, String allValue, byte[] protobufBufferArray,
FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) {
if (exceptions.matches(path))
return false;
if (matchedGroup == createShorts || matchedGroup == emojiPicker || matchedGroup == thanks) {
return path.startsWith(COMMENT_COMPOSER_PATH);
} else if (matchedGroup == commentsPreviewDots) {
return path.startsWith(VIDEO_METADATA_CAROUSEL_PATH);
} else if (matchedGroup == previewCommentText) {
return COMMENT_PREVIEW_TEXT_PATTERN.matcher(path).find();
}
return super.isFiltered(path, identifier, allValue, protobufBufferArray, matchedList, matchedGroup, matchedIndex);
}
}