mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-08 11:05:49 +01:00
perf(general-ads): hook pathBuilder
This removes the hook for the bytebuffer
This commit is contained in:
parent
3022afc7c4
commit
c7756e1299
@ -1,64 +1,39 @@
|
|||||||
package app.revanced.integrations.patches;
|
package app.revanced.integrations.patches;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class GeneralBytecodeAdsPatch {
|
public class GeneralBytecodeAdsPatch {
|
||||||
|
|
||||||
//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
||||||
public static boolean containsAd(String value, ByteBuffer buffer) {
|
public static boolean isAdComponent(StringBuilder pathBuilder) {
|
||||||
return containsLithoAd(value, buffer);
|
var path = pathBuilder.toString();
|
||||||
}
|
if (path.isEmpty()) return false;
|
||||||
|
|
||||||
private static boolean containsLithoAd(String value, ByteBuffer buffer) {
|
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Searching for an ad in: " + path);
|
||||||
boolean enabled = false;
|
|
||||||
for (SettingsEnum setting : SettingsEnum.getAdRemovalSettings()) {
|
|
||||||
if (setting.getBoolean()) {
|
|
||||||
enabled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (value == null || value.isEmpty() || !enabled) return false;
|
|
||||||
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Searching for AD: " + value);
|
|
||||||
|
|
||||||
List<String> blockList = new ArrayList<>();
|
List<String> blockList = new ArrayList<>();
|
||||||
List<String> bufferBlockList = new ArrayList<>();
|
|
||||||
|
|
||||||
if (SettingsEnum.ADREMOVER_AD_REMOVAL.getBoolean()) {
|
if (SettingsEnum.ADREMOVER_AD_REMOVAL.getBoolean()) {
|
||||||
blockList.add("_ad");
|
blockList.add("video_display_full_buttoned_layout");
|
||||||
blockList.add("ad_badge");
|
blockList.add("ad_");
|
||||||
blockList.add("ads_video_with_context");
|
blockList.add("ads_video_with_context");
|
||||||
blockList.add("cell_divider");
|
blockList.add("cell_divider");
|
||||||
blockList.add("reels_player_overlay");
|
blockList.add("reels_player_overlay");
|
||||||
blockList.add("shelf_header");
|
blockList.add("shelf_header");
|
||||||
blockList.add("text_display_ad_with_themed_cta_banner_image");
|
|
||||||
blockList.add("text_search_ad_with_description_first");
|
|
||||||
blockList.add("watch_metadata_app_promo");
|
blockList.add("watch_metadata_app_promo");
|
||||||
blockList.add("video_display_full_layout");
|
blockList.add("video_display_full_layout");
|
||||||
|
}
|
||||||
|
|
||||||
bufferBlockList.add("ad_cpn");
|
|
||||||
}
|
|
||||||
if (SettingsEnum.ADREMOVER_SUGGESTED_FOR_YOU_REMOVAL.getBoolean()) {
|
|
||||||
bufferBlockList.add("watch-vrecH");
|
|
||||||
}
|
|
||||||
if (SettingsEnum.ADREMOVER_MOVIE_REMOVAL.getBoolean()) {
|
if (SettingsEnum.ADREMOVER_MOVIE_REMOVAL.getBoolean()) {
|
||||||
blockList.add("browsy_bar");
|
blockList.add("browsy_bar");
|
||||||
blockList.add("compact_movie");
|
blockList.add("compact_movie");
|
||||||
blockList.add("horizontal_movie_shelf");
|
blockList.add("horizontal_movie_shelf");
|
||||||
blockList.add("movie_and_show_upsell_card");
|
blockList.add("movie_and_show_upsell_card");
|
||||||
|
|
||||||
bufferBlockList.add("YouTube Movies");
|
|
||||||
}
|
}
|
||||||
if (containsAny(value, "home_video_with_context", "related_video_with_context") &&
|
|
||||||
anyMatch(bufferBlockList, new String(buffer.array(), StandardCharsets.UTF_8)::contains)
|
|
||||||
) return true;
|
|
||||||
|
|
||||||
if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) {
|
if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) {
|
||||||
blockList.add("comments_");
|
blockList.add("comments_");
|
||||||
@ -104,7 +79,7 @@ public class GeneralBytecodeAdsPatch {
|
|||||||
blockList.add("channel_guidelines_entry_banner");
|
blockList.add("channel_guidelines_entry_banner");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containsAny(value,
|
if (containsAny(path,
|
||||||
"home_video_with_context",
|
"home_video_with_context",
|
||||||
"related_video_with_context",
|
"related_video_with_context",
|
||||||
"search_video_with_context",
|
"search_video_with_context",
|
||||||
@ -115,24 +90,13 @@ public class GeneralBytecodeAdsPatch {
|
|||||||
"-button"
|
"-button"
|
||||||
)) return false;
|
)) return false;
|
||||||
|
|
||||||
if (anyMatch(blockList, value::contains)) {
|
if (anyMatch(blockList, path::contains)) {
|
||||||
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value);
|
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SettingsEnum.DEBUG.getBoolean()) {
|
|
||||||
if (value.contains("related_video_with_context")) {
|
|
||||||
LogHelper.debug(GeneralBytecodeAdsPatch.class, value + " | " + bytesToHex(buffer.array()));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogHelper.debug(GeneralBytecodeAdsPatch.class, value + " returns false.");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LogHelper.printException(GeneralBytecodeAdsPatch.class, ex.getMessage(), ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean containsAny(String value, String... targets) {
|
private static boolean containsAny(String value, String... targets) {
|
||||||
for (String string : targets)
|
for (String string : targets)
|
||||||
|
@ -41,7 +41,6 @@ public enum SettingsEnum {
|
|||||||
ADREMOVER_INFO_PANEL_REMOVAL("revanced_adremover_info_panel", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_INFO_PANEL_REMOVAL("revanced_adremover_info_panel", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_MEDICAL_PANEL_REMOVAL("revanced_adremover_medical_panel", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_MEDICAL_PANEL_REMOVAL("revanced_adremover_medical_panel", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_PAID_CONTECT_REMOVAL("revanced_adremover_paid_content", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_PAID_CONTECT_REMOVAL("revanced_adremover_paid_content", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_SUGGESTED_FOR_YOU_REMOVAL("revanced_adremover_suggested", true, ReturnType.BOOLEAN, true),
|
|
||||||
ADREMOVER_HIDE_SUGGESTIONS("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_HIDE_SUGGESTIONS("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN, true),
|
||||||
|
Loading…
Reference in New Issue
Block a user