From b7a8995f798e386ee1d9ab5bbd857c1736cc5a29 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 26 Mar 2024 01:52:41 +0100 Subject: [PATCH] fix(YouTube - Hide Shorts components): Correctly hide join button --- .../components/LayoutComponentsFilter.java | 33 +++++++++++++------ .../patches/components/ShortsFilter.java | 7 ++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java index def0c6d4..fb1cd0fb 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java @@ -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( @@ -39,6 +40,7 @@ public final class LayoutComponentsFilter extends Filter { ); } + @RequiresApi(api = Build.VERSION_CODES.N) public LayoutComponentsFilter() { exceptions.addPatterns( @@ -201,9 +203,14 @@ public final class LayoutComponentsFilter extends Filter { "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( @@ -265,12 +272,6 @@ public final class LayoutComponentsFilter extends Filter { } } - 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) @@ -278,6 +279,18 @@ public final class LayoutComponentsFilter extends Filter { 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; diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java index 27f880c4..0f425641 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java @@ -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; @@ -66,7 +67,7 @@ public final class ShortsFilter extends Filter { "/frame0.jpg"); // Shorts player components. - var joinButton = new StringFilterGroup( + joinButton = new StringFilterGroup( Settings.HIDE_SHORTS_JOIN_BUTTON, "sponsor_button" ); @@ -182,7 +183,9 @@ public final class ShortsFilter extends Filter { // 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 );