mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-06 18:15:51 +01:00
refactor(youtube/general-ads): restructure class GeneralAdsPatch
This commit is contained in:
parent
2c8b23426f
commit
b59ee31d57
@ -119,7 +119,7 @@ final class LithoBlockRegister implements Iterable<BlockRule> {
|
|||||||
|
|
||||||
public final class LithoFilterPatch {
|
public final class LithoFilterPatch {
|
||||||
private static final Filter[] filters = new Filter[]{
|
private static final Filter[] filters = new Filter[]{
|
||||||
new GeneralBytecodeAdsPatch(),
|
new GeneralAdsPatch(),
|
||||||
new ButtonsPatch(),
|
new ButtonsPatch(),
|
||||||
new CommentsPatch(),
|
new CommentsPatch(),
|
||||||
};
|
};
|
||||||
@ -221,8 +221,27 @@ final class ButtonsPatch extends Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class GeneralBytecodeAdsPatch extends Filter {
|
final class GeneralAdsPatch extends Filter {
|
||||||
public GeneralBytecodeAdsPatch() {
|
private final String[] IGNORE = {
|
||||||
|
"home_video_with_context",
|
||||||
|
"related_video_with_context",
|
||||||
|
"comment_thread", // skip blocking anything in the comments
|
||||||
|
"download_",
|
||||||
|
"library_recent_shelf",
|
||||||
|
"menu",
|
||||||
|
"root",
|
||||||
|
"-count",
|
||||||
|
"-space",
|
||||||
|
"-button",
|
||||||
|
"playlist_add_to_option_wrapper" // do not block on "add to playlist" flyout menu
|
||||||
|
};
|
||||||
|
|
||||||
|
private final BlockRule custom = new CustomBlockRule(
|
||||||
|
SettingsEnum.ADREMOVER_CUSTOM_ENABLED,
|
||||||
|
SettingsEnum.ADREMOVER_CUSTOM_REMOVAL
|
||||||
|
);
|
||||||
|
|
||||||
|
public GeneralAdsPatch() {
|
||||||
var communityPosts = new BlockRule(SettingsEnum.ADREMOVER_COMMUNITY_POSTS_REMOVAL, "post_base_wrapper");
|
var communityPosts = new BlockRule(SettingsEnum.ADREMOVER_COMMUNITY_POSTS_REMOVAL, "post_base_wrapper");
|
||||||
var communityGuidelines = new BlockRule(SettingsEnum.ADREMOVER_COMMUNITY_GUIDELINES_REMOVAL, "community_guidelines");
|
var communityGuidelines = new BlockRule(SettingsEnum.ADREMOVER_COMMUNITY_GUIDELINES_REMOVAL, "community_guidelines");
|
||||||
var compactBanner = new BlockRule(SettingsEnum.ADREMOVER_COMPACT_BANNER_REMOVAL, "compact_banner");
|
var compactBanner = new BlockRule(SettingsEnum.ADREMOVER_COMPACT_BANNER_REMOVAL, "compact_banner");
|
||||||
@ -234,28 +253,21 @@ final class GeneralBytecodeAdsPatch extends Filter {
|
|||||||
var suggestions = new BlockRule(SettingsEnum.ADREMOVER_SUGGESTIONS_REMOVAL, "horizontal_video_shelf");
|
var suggestions = new BlockRule(SettingsEnum.ADREMOVER_SUGGESTIONS_REMOVAL, "horizontal_video_shelf");
|
||||||
var latestPosts = new BlockRule(SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS, "post_shelf");
|
var latestPosts = new BlockRule(SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS, "post_shelf");
|
||||||
var channelGuidelines = new BlockRule(SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES, "channel_guidelines_entry_banner");
|
var channelGuidelines = new BlockRule(SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES, "channel_guidelines_entry_banner");
|
||||||
var buttonedAd = new BlockRule(SettingsEnum.ADREMOVER_BUTTONED_REMOVAL,
|
var artistCard = new BlockRule(SettingsEnum.HIDE_ARTIST_CARD, "official_card");
|
||||||
"video_display_full_buttoned_layout",
|
|
||||||
"full_width_square_image_layout",
|
|
||||||
"_ad_with"
|
|
||||||
); var artistCard = new BlockRule(SettingsEnum.HIDE_ARTIST_CARD, "official_card");
|
|
||||||
var selfSponsor = new BlockRule(SettingsEnum.ADREMOVER_SELF_SPONSOR_REMOVAL, "cta_shelf_card");
|
var selfSponsor = new BlockRule(SettingsEnum.ADREMOVER_SELF_SPONSOR_REMOVAL, "cta_shelf_card");
|
||||||
var chapterTeaser = new BlockRule(SettingsEnum.ADREMOVER_CHAPTER_TEASER_REMOVAL, "expandable_metadata");
|
var chapterTeaser = new BlockRule(SettingsEnum.ADREMOVER_CHAPTER_TEASER_REMOVAL, "expandable_metadata");
|
||||||
var graySeparator = new BlockRule(SettingsEnum.ADREMOVER_GRAY_SEPARATOR,
|
var graySeparator = new BlockRule(SettingsEnum.ADREMOVER_GRAY_SEPARATOR,
|
||||||
"cell_divider" // layout residue (gray line above the buttoned ad),
|
"cell_divider" // layout residue (gray line above the buttoned ad),
|
||||||
);
|
);
|
||||||
|
var buttonedAd = new BlockRule(SettingsEnum.ADREMOVER_BUTTONED_REMOVAL,
|
||||||
|
"video_display_full_buttoned_layout",
|
||||||
|
"full_width_square_image_layout",
|
||||||
|
"_ad_with"
|
||||||
|
);
|
||||||
var generalAds = new BlockRule(
|
var generalAds = new BlockRule(
|
||||||
SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL,
|
SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL,
|
||||||
// could be required
|
|
||||||
//"full_width_square_image_layout",
|
|
||||||
"video_display_full_buttoned_layout",
|
|
||||||
"_ad",
|
|
||||||
"ad_",
|
|
||||||
"ads_video_with_context",
|
"ads_video_with_context",
|
||||||
"banner_text_icon",
|
"banner_text_icon",
|
||||||
"cell_divider",
|
|
||||||
"reels_player_overlay",
|
|
||||||
"watch_metadata_app_promo",
|
"watch_metadata_app_promo",
|
||||||
"video_display_full_layout"
|
"video_display_full_layout"
|
||||||
);
|
);
|
||||||
@ -288,8 +300,14 @@ final class GeneralBytecodeAdsPatch extends Filter {
|
|||||||
selfSponsor
|
selfSponsor
|
||||||
);
|
);
|
||||||
|
|
||||||
var carouselAd = new BlockRule(SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL, "carousel_ad");
|
var carouselAd = new BlockRule(SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL,
|
||||||
var shorts = new BlockRule(SettingsEnum.ADREMOVER_SHORTS_REMOVAL, "shorts_shelf", "inline_shorts");
|
"carousel_ad"
|
||||||
|
);
|
||||||
|
var shorts = new BlockRule(SettingsEnum.ADREMOVER_SHORTS_REMOVAL,
|
||||||
|
"reels_player_overlay",
|
||||||
|
"shorts_shelf",
|
||||||
|
"inline_shorts"
|
||||||
|
);
|
||||||
|
|
||||||
this.identifierRegister.registerAll(
|
this.identifierRegister.registerAll(
|
||||||
shorts,
|
shorts,
|
||||||
@ -297,32 +315,38 @@ final class GeneralBytecodeAdsPatch extends Filter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BlockRule custom = new CustomBlockRule(
|
|
||||||
SettingsEnum.ADREMOVER_CUSTOM_ENABLED,
|
|
||||||
SettingsEnum.ADREMOVER_CUSTOM_REMOVAL
|
|
||||||
);
|
|
||||||
|
|
||||||
public boolean filter(final String path, final String identifier) {
|
public boolean filter(final String path, final String identifier) {
|
||||||
// Do not block on these
|
BlockResult result;
|
||||||
if (ReVancedUtils.containsAny(path,
|
|
||||||
"home_video_with_context",
|
|
||||||
"related_video_with_context",
|
|
||||||
"comment_thread", // skip blocking anything in the comments
|
|
||||||
"download_",
|
|
||||||
"library_recent_shelf",
|
|
||||||
"menu",
|
|
||||||
"root",
|
|
||||||
"-count",
|
|
||||||
"-space",
|
|
||||||
"-button",
|
|
||||||
"playlist_add_to_option_wrapper" // do not block on "add to playlist" flyout menu
|
|
||||||
)) return false;
|
|
||||||
|
|
||||||
if (!(Extensions.any(pathRegister, path) || Extensions.any(identifierRegister, identifier)))
|
if (custom.isEnabled() && custom.check(path).isBlocked())
|
||||||
return false;
|
result = BlockResult.CUSTOM;
|
||||||
|
else if (ReVancedUtils.containsAny(path, IGNORE))
|
||||||
|
result = BlockResult.IGNORED;
|
||||||
|
else if (pathRegister.contains(path) || identifierRegister.contains(identifier))
|
||||||
|
result = BlockResult.DEFINED;
|
||||||
|
else
|
||||||
|
result = BlockResult.UNBLOCKED;
|
||||||
|
|
||||||
LogHelper.debug(GeneralBytecodeAdsPatch.class, String.format("Blocked (ID: %s): %s", identifier, path));
|
LogHelper.debug(
|
||||||
|
GeneralAdsPatch.class,
|
||||||
|
String.format("%s (ID: %s): %s", result.message, identifier, path)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return result.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum BlockResult {
|
||||||
|
UNBLOCKED(false, "Unblocked"),
|
||||||
|
IGNORED(false, "Ignored"),
|
||||||
|
DEFINED(true, "Blocked"),
|
||||||
|
CUSTOM(true, "Custom");
|
||||||
|
|
||||||
|
final Boolean filter;
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
BlockResult(boolean filter, String message) {
|
||||||
|
this.filter = filter;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package app.revanced.integrations.settings;
|
package app.revanced.integrations.settings;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -44,11 +43,11 @@ public enum SettingsEnum {
|
|||||||
ADREMOVER_PAID_CONTENT_REMOVAL("revanced_adremover_paid_content", true, ReturnType.BOOLEAN),
|
ADREMOVER_PAID_CONTENT_REMOVAL("revanced_adremover_paid_content", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_SUGGESTIONS_REMOVAL("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN),
|
ADREMOVER_SUGGESTIONS_REMOVAL("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN),
|
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_GRAY_SEPARATOR("revanced_adremover_separator", true, ReturnType.BOOLEAN),
|
|
||||||
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN),
|
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_SELF_SPONSOR_REMOVAL("revanced_adremover_self_sponsor", true, ReturnType.BOOLEAN),
|
ADREMOVER_SELF_SPONSOR_REMOVAL("revanced_adremover_self_sponsor", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_CHAPTER_TEASER_REMOVAL("revanced_adremover_chapter_teaser", true, ReturnType.BOOLEAN),
|
ADREMOVER_CHAPTER_TEASER_REMOVAL("revanced_adremover_chapter_teaser", true, ReturnType.BOOLEAN),
|
||||||
ADREMOVER_BUTTONED_REMOVAL("revanced_adremover_buttoned", true, ReturnType.BOOLEAN),
|
ADREMOVER_BUTTONED_REMOVAL("revanced_adremover_buttoned", true, ReturnType.BOOLEAN),
|
||||||
|
ADREMOVER_GRAY_SEPARATOR("revanced_adremover_separator", true, ReturnType.BOOLEAN),
|
||||||
|
|
||||||
// Action buttons
|
// Action buttons
|
||||||
HIDE_LIKE_BUTTON("revanced_like_button", false, ReturnType.BOOLEAN, false),
|
HIDE_LIKE_BUTTON("revanced_like_button", false, ReturnType.BOOLEAN, false),
|
||||||
|
Loading…
Reference in New Issue
Block a user