Skip to content

Commit

Permalink
fix(general-ads): block remaining ads
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 2, 2022
1 parent c3e302d commit 18a749f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,47 @@
import app.revanced.integrations.utils.LogHelper;

public class GeneralBytecodeAdsPatch {

//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
public static boolean isAdComponent(StringBuilder pathBuilder) {
public static boolean isAdComponent(StringBuilder pathBuilder, String identifier) {
var path = pathBuilder.toString();
if (path.isEmpty()) return false;

LogHelper.debug(GeneralBytecodeAdsPatch.class, "Searching for an ad in: " + path);
LogHelper.debug(GeneralBytecodeAdsPatch.class, String.format("Searching (ID: %s): %s", identifier, path));

if (containsAny(path,
"home_video_with_context",
"related_video_with_context",
"search_video_with_context",
"menu",
"root",
"-count",
"-space",
"-button",
"library_recent_shelf",
"download_button"
)) return false;

List<String> blockList = new ArrayList<>();

if (SettingsEnum.ADREMOVER_AD_REMOVAL.getBoolean()) {
for (var ad : SettingsEnum.ADREMOVER_CUSTOM.getString().split(",")) {
if (ad.isEmpty()) continue;
blockList.add(ad);
}

if (SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL.getBoolean()) {
if (identifier != null && identifier.contains("carousel_ad")) {
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking: " + identifier);
return true;
}

blockList.add("video_display_full_buttoned_layout");
blockList.add("_ad");
blockList.add("ad_");
blockList.add("ads_video_with_context");
blockList.add("cell_divider");
blockList.add("reels_player_overlay");
// could be required
// blockList.add("full_width_square_image_layout");
blockList.add("shelf_header");
blockList.add("watch_metadata_app_promo");
blockList.add("video_display_full_layout");
Expand Down Expand Up @@ -79,19 +104,8 @@ public static boolean isAdComponent(StringBuilder pathBuilder) {
blockList.add("channel_guidelines_entry_banner");
}

if (containsAny(path,
"home_video_with_context",
"related_video_with_context",
"search_video_with_context",
"menu",
"root",
"-count",
"-space",
"-button"
)) return false;

if (anyMatch(blockList, path::contains)) {
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + path);
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking: " + path);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public enum SettingsEnum {
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),

//Ad settings
ADREMOVER_CUSTOM("revanced_adremover_custom_removal", "", ReturnType.STRING, false),
HOME_ADS_REMOVAL("revanced_home_ads_removal", true, ReturnType.BOOLEAN, true),
VIDEO_ADS_REMOVAL("revanced_video_ads_removal", true, ReturnType.BOOLEAN, true),
ADREMOVER_AD_REMOVAL("revanced_adremover_ad_removal", true, ReturnType.BOOLEAN, true),
ADREMOVER_GENERAL_ADS_REMOVAL("revanced_adremover_ad_removal", true, ReturnType.BOOLEAN, true),
ADREMOVER_MERCHANDISE_REMOVAL("revanced_adremover_merchandise", true, ReturnType.BOOLEAN, true),
ADREMOVER_COMMUNITY_POSTS_REMOVAL("revanced_adremover_community_posts_removal", true, ReturnType.BOOLEAN, true),
ADREMOVER_COMPACT_BANNER_REMOVAL("revanced_adremover_compact_banner_removal", true, ReturnType.BOOLEAN, true),
Expand Down

0 comments on commit 18a749f

Please sign in to comment.