Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

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.
Expand All @@ -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;
}

/**
Expand All @@ -40,7 +71,7 @@ public static boolean hideVideoAds() {
* 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.injectHideViewCall
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
Expand Down Expand Up @@ -132,6 +133,24 @@ val adsPatch = bytecodePatch(

// endregion

// region patch for hide end screen store banner

fullScreenEngagementAdContainerFingerprint.methodOrThrow().apply {
val addListIndex = indexOfAddListInstruction(this)
val addListInstruction =
getInstruction<FiveRegisterInstruction>(addListIndex)
val listRegister = addListInstruction.registerC
val objectRegister = addListInstruction.registerD

replaceInstruction(
addListIndex,
"invoke-static { v$listRegister, v$objectRegister }, " +
"$ADS_CLASS_DESCRIPTOR->hideEndScreenStoreBanner(Ljava/util/List;Ljava/lang/Object;)V"
)
}

// endregion

findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "HideFullscreenAdsDefaultBoolean"
}.replaceInstruction(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package app.revanced.patches.youtube.ads.general

import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementAdContainer
import app.revanced.patches.youtube.utils.resourceid.interstitialsContainer
import app.revanced.patches.youtube.utils.resourceid.slidingDialogAnimation
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal val compactYpcOfferModuleViewFingerprint = legacyFingerprint(
name = "compactYpcOfferModuleViewFingerprint",
Expand All @@ -24,6 +29,23 @@ internal val compactYpcOfferModuleViewFingerprint = legacyFingerprint(
}
)

internal val fullScreenEngagementAdContainerFingerprint = legacyFingerprint(
name = "fullScreenEngagementAdContainerFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
literals = listOf(fullScreenEngagementAdContainer),
customFingerprint = { method, _ ->
indexOfAddListInstruction(method) >= 0
}
)

internal fun indexOfAddListInstruction(method: Method) =
method.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "add"
}

internal val interstitialsContainerFingerprint = legacyFingerprint(
name = "interstitialsContainerFingerprint",
returnType = "V",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ var floatyBarTopMargin = -1L
private set
var fullScreenButton = -1L
private set
var fullScreenEngagementAdContainer = -1L
private set
var fullScreenEngagementOverlay = -1L
private set
var fullScreenEngagementPanel = -1L
Expand Down Expand Up @@ -429,6 +431,10 @@ internal val sharedResourceIdPatch = resourcePatch(
ID,
"fullscreen_button"
]
fullScreenEngagementAdContainer = resourceMappings[
ID,
"fullscreen_engagement_ad_container"
]
fullScreenEngagementOverlay = resourceMappings[
LAYOUT,
"fullscreen_engagement_overlay"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Please download %2$s from the website."</string>
<!-- PreferenceScreen: Ads -->
<string name="revanced_preference_screen_ads_title">Ads</string>

<string name="revanced_hide_end_screen_store_banner_title">Hide end screen store banner</string>
<string name="revanced_hide_end_screen_store_banner_summary_on">Store banner is hidden.</string>
<string name="revanced_hide_end_screen_store_banner_summary_off">Store banner is shown.</string>
<string name="revanced_hide_fullscreen_ads_title">Hide fullscreen ads</string>
<string name="revanced_hide_fullscreen_ads_summary_on">Fullscreen ads are hidden.</string>
<string name="revanced_hide_fullscreen_ads_summary_off">Fullscreen ads are shown.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<!-- PREFERENCE_SCREEN: ADS
<PreferenceScreen android:title="@string/revanced_preference_screen_ads_title" android:key="revanced_preference_screen_ads">
<SwitchPreference android:title="@string/revanced_hide_end_screen_store_banner_title" android:key="revanced_hide_end_screen_store_banner" android:summaryOn="@string/revanced_hide_end_screen_store_banner_summary_on" android:summaryOff="@string/revanced_hide_end_screen_store_banner_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_fullscreen_ads_title" android:key="revanced_hide_fullscreen_ads" android:summaryOn="@string/revanced_hide_fullscreen_ads_summary_on" android:summaryOff="@string/revanced_hide_fullscreen_ads_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_general_ads_title" android:key="revanced_hide_general_ads" android:summaryOn="@string/revanced_hide_general_ads_summary_on" android:summaryOff="@string/revanced_hide_general_ads_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_merchandise_shelf_title" android:key="revanced_hide_merchandise_shelf" android:summaryOn="@string/revanced_hide_merchandise_shelf_summary_on" android:summaryOff="@string/revanced_hide_merchandise_shelf_summary_off" />
Expand Down