fix(YouTube - Hide Ads): Hide end screen store banner without leaving empty space (#4367)

This commit is contained in:
LisoUseInAIKyrios
2025-01-29 09:40:59 +02:00
committed by GitHub
parent 9b6f78a7e8
commit 7e68390641
5 changed files with 88 additions and 32 deletions

View File

@ -5,10 +5,13 @@ import app.revanced.extension.youtube.settings.Settings;
@SuppressWarnings("unused")
public class VideoAdsPatch {
// Used by app.revanced.patches.youtube.ad.general.video.patch.VideoAdsPatch
// depends on Whitelist patch (still needs to be written)
private static final boolean SHOW_VIDEO_ADS = !Settings.HIDE_VIDEO_ADS.get();
/**
* Injection point.
*/
public static boolean shouldShowAds() {
return !Settings.HIDE_VIDEO_ADS.get(); // TODO && Whitelist.shouldShowAds();
return SHOW_VIDEO_ADS;
}
}

View File

@ -8,10 +8,12 @@ import android.view.View;
import androidx.annotation.Nullable;
import app.revanced.extension.youtube.settings.Settings;
import java.util.List;
import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.StringTrieSearch;
import app.revanced.extension.youtube.settings.Settings;
@SuppressWarnings("unused")
public final class AdsFilter extends Filter {
@ -22,14 +24,16 @@ public final class AdsFilter extends Filter {
// endregion
// https://encrypted-tbn0.gstatic.com/shopping?q=abc
private static final String STORE_BANNER_DOMAIN = "gstatic.com/shopping";
private static final boolean HIDE_END_SCREEN_STORE_BANNER =
Settings.HIDE_END_SCREEN_STORE_BANNER.get();
private final StringTrieSearch exceptions = new StringTrieSearch();
private final StringFilterGroup playerShoppingShelf;
private final ByteArrayFilterGroup playerShoppingShelfBuffer;
private final StringFilterGroup fullscreenOverlay;
private final ByteArrayFilterGroup endScreenStoreBannerBuffer;
private final StringFilterGroup channelProfile;
private final ByteArrayFilterGroup visitStoreButton;
@ -116,32 +120,22 @@ public final class AdsFilter extends Filter {
);
playerShoppingShelf = new StringFilterGroup(
null,
Settings.HIDE_PLAYER_STORE_SHELF,
"horizontal_shelf.eml"
);
playerShoppingShelfBuffer = new ByteArrayFilterGroup(
Settings.HIDE_PLAYER_STORE_SHELF,
null,
"shopping_item_card_list.eml"
);
fullscreenOverlay = new StringFilterGroup(
Settings.HIDE_END_SCREEN_STORE_BANNER,
"fullscreen_overlay.eml"
);
endScreenStoreBannerBuffer = new ByteArrayFilterGroup(
null,
"gstatic.com/shopping"
);
channelProfile = new StringFilterGroup(
null,
Settings.HIDE_VISIT_STORE_BUTTON,
"channel_profile.eml"
);
visitStoreButton = new ByteArrayFilterGroup(
Settings.HIDE_VISIT_STORE_BUTTON,
null,
"header_store_button"
);
@ -167,7 +161,6 @@ public final class AdsFilter extends Filter {
viewProducts,
selfSponsor,
fullscreenAd,
fullscreenOverlay,
channelProfile,
webLinkPanel,
shoppingLinks,
@ -186,10 +179,8 @@ public final class AdsFilter extends Filter {
return false;
}
if (matchedGroup == fullscreenOverlay) {
if (contentIndex == 0 && endScreenStoreBannerBuffer.check(protobufBufferArray).isFiltered()) {
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
// Check for the index because of likelihood of false positives.
if (matchedGroup == shoppingLinks && contentIndex != 0) {
return false;
}
@ -209,13 +200,25 @@ public final class AdsFilter extends Filter {
return false;
}
// Check for the index because of likelihood of false positives.
if (matchedGroup == shoppingLinks && contentIndex != 0)
return false;
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
/**
* Injection point.
*
* @param elementsList List of components of the end screen container.
* @param protobufList Component (ProtobufList).
*/
public static void hideEndScreenStoreBanner(List<Object> elementsList, Object protobufList) {
if (HIDE_END_SCREEN_STORE_BANNER && protobufList.toString().contains(STORE_BANNER_DOMAIN)) {
Logger.printDebug(() -> "Hiding store banner");
return;
}
elementsList.add(protobufList);
}
/**
* Hide the view, which shows ads in the homepage.
*

View File

@ -64,7 +64,7 @@ public class Settings extends BaseSettings {
// Ads
public static final BooleanSetting HIDE_BUTTONED_ADS = new BooleanSetting("revanced_hide_buttoned_ads", TRUE);
public static final BooleanSetting HIDE_END_SCREEN_STORE_BANNER = new BooleanSetting("revanced_hide_end_screen_store_banner", FALSE);
public static final BooleanSetting HIDE_END_SCREEN_STORE_BANNER = new BooleanSetting("revanced_hide_end_screen_store_banner", TRUE, true);
public static final BooleanSetting HIDE_FULLSCREEN_ADS = new BooleanSetting("revanced_hide_fullscreen_ads", TRUE);
public static final BooleanSetting HIDE_GENERAL_ADS = new BooleanSetting("revanced_hide_general_ads", TRUE);
public static final BooleanSetting HIDE_GET_PREMIUM = new BooleanSetting("revanced_hide_get_premium", TRUE);