Skip to content

Commit

Permalink
fix(YouTube - Hide Shorts components): Correctly hide join button
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Mar 26, 2024
1 parent 59165de commit b7a8995
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public final class LayoutComponentsFilter extends Filter {
private final ByteArrayFilterGroup searchResultRecommendations;
private final StringFilterGroup searchResultVideo;
private final StringFilterGroup compactChannelBarInner;
private final ByteArrayFilterGroup joinMembership;
private final StringFilterGroup compactChannelBarInnerButton;
private final ByteArrayFilterGroup joinMembershipButton;

static {
mixPlaylistsExceptions.addPatterns(
Expand All @@ -39,6 +40,7 @@ public final class LayoutComponentsFilter extends Filter {
);
}


@RequiresApi(api = Build.VERSION_CODES.N)
public LayoutComponentsFilter() {
exceptions.addPatterns(
Expand Down Expand Up @@ -201,9 +203,14 @@ public LayoutComponentsFilter() {
"compact_channel_bar_inner"
);

joinMembership = new ByteArrayFilterGroup(
Settings.HIDE_JOIN_MEMBERSHIP_BUTTON,
"Join this channel"
compactChannelBarInnerButton = new StringFilterGroup(
null,
"|button.eml|"
);

joinMembershipButton = new ByteArrayFilterGroup(
null,
"sponsorships"
);

final var channelWatermark = new StringFilterGroup(
Expand Down Expand Up @@ -265,19 +272,25 @@ public boolean isFiltered(@Nullable String identifier, String path, byte[] proto
}
}

if (matchedGroup == compactChannelBarInner) {
if (joinMembership.check(protobufBufferArray).isFiltered()){
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
}

// The groups are excluded from the filter due to the exceptions list below.
// Filter them separately here.
if (matchedGroup == notifyMe || matchedGroup == inFeedSurvey || matchedGroup == expandableMetadata)
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);

if (exceptions.matches(path)) return false; // Exceptions are not filtered.

if (matchedGroup == compactChannelBarInner) {
if (compactChannelBarInnerButton.check(path).isFiltered()) {
// The filter may be broad, but in the context of a compactChannelBarInnerButton,
// it's safe to assume that the button is the only thing that should be hidden.
if (joinMembershipButton.check(protobufBufferArray).isFiltered()) {
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
}

return false;
}

// TODO: This also hides the feed Shorts shelf header
if (matchedGroup == searchResultShelfHeader && contentIndex != 0) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class ShortsFilter extends Filter {
private final StringFilterGroup subscribeButtonPaused;
private final StringFilterGroup soundButton;
private final StringFilterGroup infoPanel;
private final StringFilterGroup joinButton;
private final StringFilterGroup shelfHeader;

private final StringFilterGroup actionBar;
Expand Down Expand Up @@ -66,7 +67,7 @@ public ShortsFilter() {
"/frame0.jpg");

// Shorts player components.
var joinButton = new StringFilterGroup(
joinButton = new StringFilterGroup(
Settings.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);
Expand Down Expand Up @@ -182,7 +183,9 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff

// Filter other path groups from pathFilterGroupList, only when reelChannelBar is visible
// to avoid false positives.
if (matchedGroup == subscribeButton) {
if (matchedGroup == subscribeButton ||
matchedGroup == joinButton
) {
if (path.startsWith(REEL_CHANNEL_BAR_PATH)) return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
Expand Down

0 comments on commit b7a8995

Please sign in to comment.