From 13afac906a0087ea7bc888c80e293f7b05c0a46e Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Wed, 23 Aug 2023 08:35:00 +0500 Subject: [PATCH] fix(YouTube - Hide Shorts components): Hide `shorts header` (#455) Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Co-authored-by: oSumAtrIX --- .../patches/components/ShortsFilter.java | 82 +++++++++++-------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/components/ShortsFilter.java b/app/src/main/java/app/revanced/integrations/patches/components/ShortsFilter.java index cfe9ebd3..591221dc 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/ShortsFilter.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/ShortsFilter.java @@ -12,45 +12,21 @@ import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar; import app.revanced.integrations.settings.SettingsEnum; public final class ShortsFilter extends Filter { - private static final String REEL_CHANNEL_BAR_PATH = "reel_channel_bar"; + private static final String REEL_CHANNEL_BAR_PATH = "reel_channel_bar.eml"; public static PivotBar pivotBar; // Set by patch. private final StringFilterGroup channelBar; private final StringFilterGroup soundButton; private final StringFilterGroup infoPanel; + private final StringFilterGroup shortsShelfHeader; public ShortsFilter() { - channelBar = new StringFilterGroup( - SettingsEnum.HIDE_SHORTS_CHANNEL_BAR, - REEL_CHANNEL_BAR_PATH - ); - - soundButton = new StringFilterGroup( - SettingsEnum.HIDE_SHORTS_SOUND_BUTTON, - "reel_pivot_button" - ); - - infoPanel = new StringFilterGroup( - SettingsEnum.HIDE_SHORTS_INFO_PANEL, - "shorts_info_panel_overview" - ); - - final var thanksButton = new StringFilterGroup( + // Home / subscription feed components. + var thanksButton = new StringFilterGroup( SettingsEnum.HIDE_SHORTS_THANKS_BUTTON, "suggested_action" ); - - final var subscribeButton = new StringFilterGroup( - SettingsEnum.HIDE_SHORTS_SUBSCRIBE_BUTTON, - "subscribe_button" - ); - - final var joinButton = new StringFilterGroup( - SettingsEnum.HIDE_SHORTS_JOIN_BUTTON, - "sponsor_button" - ); - - final var shorts = new StringFilterGroup( + var shorts = new StringFilterGroup( SettingsEnum.HIDE_SHORTS, "shorts_shelf", "inline_shorts", @@ -58,22 +34,58 @@ public final class ShortsFilter extends Filter { "shorts_video_cell", "shorts_pivot_item" ); + // Use a different filter group for this pattern, as it requires an additional check after matching. + shortsShelfHeader = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS, + "shelf_header.eml" + ); + identifierFilterGroups.addAll(shorts, shortsShelfHeader, thanksButton); + + // Shorts player components. + var joinButton = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS_JOIN_BUTTON, + "sponsor_button" + ); + var subscribeButton = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS_SUBSCRIBE_BUTTON, + "subscribe_button" + ); + channelBar = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS_CHANNEL_BAR, + REEL_CHANNEL_BAR_PATH + ); + soundButton = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS_SOUND_BUTTON, + "reel_pivot_button" + ); + infoPanel = new StringFilterGroup( + SettingsEnum.HIDE_SHORTS_INFO_PANEL, + "shorts_info_panel_overview" + ); pathFilterGroupList.addAll(joinButton, subscribeButton, channelBar, soundButton, infoPanel); - identifierFilterGroupList.addAll(shorts, thanksButton); } @Override boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray, FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) { - if (matchedGroup == soundButton || matchedGroup == infoPanel || matchedGroup == channelBar) return true; + if (matchedList == pathFilterGroupList) { + // Always filter if matched. + if (matchedGroup == soundButton || matchedGroup == infoPanel || matchedGroup == channelBar) + return super.isFiltered(path, identifier, protobufBufferArray, matchedList, matchedGroup, matchedIndex); - // Filter the path only when reelChannelBar is visible. - if (pathFilterGroupList == matchedList) { - return path.contains(REEL_CHANNEL_BAR_PATH); + // Filter other path groups from pathFilterGroupList, only when reelChannelBar is visible + // to avoid false positives. + if (!path.startsWith(REEL_CHANNEL_BAR_PATH)) + return false; + } else if (matchedGroup == shortsShelfHeader) { + // Because the header is used in watch history and possibly other places, check for the index, + // which is 0 when the shelf header is used for Shorts. + if (matchedIndex != 0) return false; } - return identifierFilterGroupList == matchedList; + // Super class handles logging. + return super.isFiltered(path, identifier, protobufBufferArray, matchedList, matchedGroup, matchedIndex); } public static void hideShortsShelf(final View shortsShelfView) {