feat(YouTube - Hide ads): Add Hide end screen store banner setting (#131)

* add patch option to clean related video overlay

* feat(YouTube - Hide ads): Add `Hide end screen store banner` setting

* feat: Revert edit xml

* chore: Lint code

---------

Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
This commit is contained in:
MondayNitro
2025-01-28 09:13:33 +05:30
committed by GitHub
parent 5255c7eca8
commit 18a854de19
7 changed files with 90 additions and 7 deletions

View File

@ -4,13 +4,25 @@ import static app.revanced.extension.shared.utils.Utils.hideViewBy0dpUnderCondit
import android.view.View;
import java.util.List;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.youtube.settings.Settings;
@SuppressWarnings("unused")
public class AdsPatch {
private static final boolean hideGeneralAdsEnabled = Settings.HIDE_GENERAL_ADS.get();
private static final boolean hideGetPremiumAdsEnabled = Settings.HIDE_GET_PREMIUM.get();
private static final boolean hideVideoAdsEnabled = Settings.HIDE_VIDEO_ADS.get();
private static final boolean HIDE_END_SCREEN_STORE_BANNER =
Settings.HIDE_END_SCREEN_STORE_BANNER.get();
private static final boolean HIDE_GENERAL_ADS =
Settings.HIDE_GENERAL_ADS.get();
private static final boolean HIDE_GET_PREMIUM =
Settings.HIDE_GET_PREMIUM.get();
private static final boolean HIDE_VIDEO_ADS =
Settings.HIDE_VIDEO_ADS.get();
// https://encrypted-tbn0.gstatic.com/shopping?q=tbn
private static final String STORE_BANNER_DOMAIN =
"gstatic.com/shopping";
/**
* Injection point.
@ -19,18 +31,37 @@ public class AdsPatch {
* @param view The view, which shows ads.
*/
public static void hideAdAttributionView(View view) {
hideViewBy0dpUnderCondition(hideGeneralAdsEnabled, view);
hideViewBy0dpUnderCondition(HIDE_GENERAL_ADS, view);
}
/**
* 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);
}
/**
* Injection point.
*/
public static boolean hideGetPremium() {
return hideGetPremiumAdsEnabled;
return HIDE_GET_PREMIUM;
}
/**
* Injection point.
*/
public static boolean hideVideoAds() {
return !hideVideoAdsEnabled;
return !HIDE_VIDEO_ADS;
}
/**
@ -40,7 +71,7 @@ public class AdsPatch {
* It is presumed to have been deprecated, and if it is confirmed that it is no longer used, remove it.
*/
public static boolean hideVideoAds(boolean original) {
return !hideVideoAdsEnabled && original;
return !HIDE_VIDEO_ADS && original;
}
}

View File

@ -48,6 +48,7 @@ import app.revanced.extension.youtube.sponsorblock.SponsorBlockSettings;
@SuppressWarnings("unused")
public class Settings extends BaseSettings {
// PreferenceScreen: Ads
public static final BooleanSetting HIDE_END_SCREEN_STORE_BANNER = new BooleanSetting("revanced_hide_end_screen_store_banner", TRUE, 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, true);
public static final BooleanSetting HIDE_MERCHANDISE_SHELF = new BooleanSetting("revanced_hide_merchandise_shelf", TRUE);