diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/AdsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/AdsFilter.java index d3f63a2ff5..540f212a0d 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/AdsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/AdsFilter.java @@ -24,6 +24,9 @@ public final class AdsFilter extends Filter { private final StringTrieSearch exceptions = new StringTrieSearch(); + private final StringFilterGroup playerShoppingShelf; + private final ByteArrayFilterGroup playerShoppingShelfBuffer; + private final StringFilterGroup channelProfile; private final ByteArrayFilterGroup visitStoreButton; @@ -110,6 +113,16 @@ public AdsFilter() { "channel_profile.eml" ); + playerShoppingShelf = new StringFilterGroup( + null, + "horizontal_shelf.eml" + ); + + playerShoppingShelfBuffer = new ByteArrayFilterGroup( + Settings.HIDE_PLAYER_STORE_SHELF, + "shopping_item_card_list.eml" + ); + visitStoreButton = new ByteArrayFilterGroup( Settings.HIDE_VISIT_STORE_BUTTON, "header_store_button" @@ -140,6 +153,7 @@ public AdsFilter() { channelProfile, webLinkPanel, shoppingLinks, + playerShoppingShelf, movieAds ); } @@ -147,6 +161,13 @@ public AdsFilter() { @Override boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray, StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) { + if (matchedGroup == playerShoppingShelf) { + if (contentIndex == 0 && playerShoppingShelfBuffer.check(protobufBufferArray).isFiltered()) { + return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex); + } + return false; + } + if (exceptions.matches(path)) return false; 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 579396b55f..415b7d8c8e 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 @@ -251,7 +251,7 @@ public LayoutComponentsFilter() { ); horizontalShelves = new StringFilterGroup( - null, // Multiple settings use this filter. + Settings.HIDE_HORIZONTAL_SHELVES, "horizontal_video_shelf.eml", "horizontal_shelf.eml", "horizontal_shelf_inline.eml", @@ -458,18 +458,11 @@ public static void hideShowMoreButton(View view) { } private static boolean hideShelves() { - // Video player can show a horizontal shopping shelf below the video. - // It appears this is the only shelf that can appear in the player, - // and no shelves are shown in the recommendations under the video. - if (PlayerType.getCurrent().isMaximizedOrFullscreen()) { - return Settings.HIDE_PLAYER_STORE_SHELF.get(); - } - - if (!Settings.HIDE_HORIZONTAL_SHELVES.get()) { - return false; - } - - if (NavigationBar.isSearchBarActive()) { + // If the player is opened while library is selected, + // then filter any recommendations below the player. + if (PlayerType.getCurrent().isMaximizedOrFullscreen() + // Or if the search is active while library is selected, then also filter. + || NavigationBar.isSearchBarActive()) { return true; }