mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-08 10:34:33 +02:00
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:
parent
5255c7eca8
commit
18a854de19
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
@ -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(
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
|
@ -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
|
||||
@ -432,6 +434,10 @@ internal val sharedResourceIdPatch = resourcePatch(
|
||||
ID,
|
||||
"fullscreen_button"
|
||||
]
|
||||
fullScreenEngagementAdContainer = resourceMappings[
|
||||
ID,
|
||||
"fullscreen_engagement_ad_container"
|
||||
]
|
||||
fullScreenEngagementOverlay = resourceMappings[
|
||||
LAYOUT,
|
||||
"fullscreen_engagement_overlay"
|
||||
|
@ -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>
|
||||
|
@ -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" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user