mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-09 21:49:25 +01:00
feat: make containsAd
more efficient & add new values
This commit is contained in:
parent
468c72e2a5
commit
8ff5f0e68d
@ -2,11 +2,12 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
compileSdkVersion 32
|
||||||
|
namespace 'vanced.integrations'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "revanced.integrationsapp"
|
applicationId "revanced.integrationsapp"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 31
|
targetSdkVersion 32
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
multiDexEnabled false
|
multiDexEnabled false
|
||||||
@ -33,6 +34,6 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'androidx.annotation:annotation:1.3.0'
|
implementation 'androidx.annotation:annotation:1.3.0'
|
||||||
implementation "androidx.constraintlayout:constraintlayout:2.1.0"
|
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
package="vanced.integrations">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||||
</manifest>
|
</manifest>
|
@ -1,10 +1,14 @@
|
|||||||
package fi.razerman.youtube.litho;
|
package fi.razerman.youtube.litho;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -13,8 +17,6 @@ import fi.razerman.youtube.Helpers.SharedPrefs;
|
|||||||
import fi.razerman.youtube.XGlobals;
|
import fi.razerman.youtube.XGlobals;
|
||||||
|
|
||||||
public class LithoAdRemoval {
|
public class LithoAdRemoval {
|
||||||
private static final byte[] endRelatedPageAd = {112, 97, 103, 101, 97, 100};
|
|
||||||
|
|
||||||
private static boolean getBoolean(String key, boolean _default) {
|
private static boolean getBoolean(String key, boolean _default) {
|
||||||
return SharedPrefs.getBoolean(Objects.requireNonNull(YouTubeTikTokRoot_Application.getAppContext()), key, _default);
|
return SharedPrefs.getBoolean(Objects.requireNonNull(YouTubeTikTokRoot_Application.getAppContext()), key, _default);
|
||||||
}
|
}
|
||||||
@ -43,8 +45,8 @@ public class LithoAdRemoval {
|
|||||||
return getBoolean("experimental_community_posts", false);
|
return getBoolean("experimental_community_posts", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExperimentalMovieUpsellRemoval() {
|
public static boolean isExperimentalMovieRemoval() {
|
||||||
return getBoolean("experimental_movie_upsell", false);
|
return getBoolean("experimental_movie", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExperimentalCompactBannerRemoval() {
|
public static boolean isExperimentalCompactBannerRemoval() {
|
||||||
@ -59,14 +61,6 @@ public class LithoAdRemoval {
|
|||||||
return getBoolean("experimental_comments", false);
|
return getBoolean("experimental_comments", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExperimentalCompactMovieRemoval() {
|
|
||||||
return getBoolean("experimental_compact_movie", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isExperimentalHorizontalMovieShelfRemoval() {
|
|
||||||
return getBoolean("experimental_horizontal_movie_shelf", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInFeedSurvey() {
|
public static boolean isInFeedSurvey() {
|
||||||
return getBoolean("experimental_in_feed_survey", false);
|
return getBoolean("experimental_in_feed_survey", false);
|
||||||
}
|
}
|
||||||
@ -79,12 +73,26 @@ public class LithoAdRemoval {
|
|||||||
return getBoolean("experimental_community_guidelines", true);
|
return getBoolean("experimental_community_guidelines", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
public static boolean containsAd(String value, ByteBuffer buffer) {
|
public static boolean containsAd(String value, ByteBuffer buffer) {
|
||||||
try {
|
try {
|
||||||
if (!(isExperimentalAdRemoval() || isExperimentalMerchandiseRemoval() || isExperimentalPaidContentRemoval() || isExperimentalCommunityPostRemoval() || isExperimentalMovieUpsellRemoval() || isExperimentalCompactBannerRemoval() || isExperimentalCommentsRemoval() || isExperimentalCompactMovieRemoval() || isExperimentalHorizontalMovieShelfRemoval() || isInFeedSurvey() || isShortsShelf() || isCommunityGuidelines()) || value == null || value.isEmpty()) {
|
if (!(isExperimentalAdRemoval() ||
|
||||||
|
isExperimentalMerchandiseRemoval() ||
|
||||||
|
isExperimentalPaidContentRemoval() || isExperimentalCommunityPostRemoval() ||
|
||||||
|
isExperimentalMovieRemoval() ||
|
||||||
|
isExperimentalCompactBannerRemoval() ||
|
||||||
|
isExperimentalCommentsRemoval() ||
|
||||||
|
isInFeedSurvey() ||
|
||||||
|
isShortsShelf() ||
|
||||||
|
isCommunityGuidelines()) ||
|
||||||
|
value == null ||
|
||||||
|
value.isEmpty()
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<String> blockList = new ArrayList<>();
|
List<String> blockList = new ArrayList<>();
|
||||||
|
List<String> bufferBlockList = new ArrayList<>();
|
||||||
|
|
||||||
if (isExperimentalAdRemoval()) {
|
if (isExperimentalAdRemoval()) {
|
||||||
blockList.add("_ad");
|
blockList.add("_ad");
|
||||||
blockList.add("ad_badge");
|
blockList.add("ad_badge");
|
||||||
@ -93,16 +101,32 @@ public class LithoAdRemoval {
|
|||||||
blockList.add("shelf_header");
|
blockList.add("shelf_header");
|
||||||
blockList.add("cell_divider");
|
blockList.add("cell_divider");
|
||||||
blockList.add("watch_metadata_app_promo");
|
blockList.add("watch_metadata_app_promo");
|
||||||
|
|
||||||
|
bufferBlockList.add("ad_cpn");
|
||||||
}
|
}
|
||||||
|
if (isExperimentalMovieRemoval()) {
|
||||||
|
blockList.add("movie_and_show_upsell_card");
|
||||||
|
blockList.add("compact_movie");
|
||||||
|
blockList.add("horizontal_movie_shelf");
|
||||||
|
|
||||||
|
bufferBlockList.add("YouTube Movies");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
value.contains("related_video_with_context") &&
|
||||||
|
bufferBlockList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(StandardCharsets.UTF_8.decode(buffer).toString()::contains)
|
||||||
|
) return true;
|
||||||
|
|
||||||
|
|
||||||
if (isExperimentalMerchandiseRemoval()) {
|
if (isExperimentalMerchandiseRemoval()) {
|
||||||
blockList.add("product_carousel");
|
blockList.add("product_carousel");
|
||||||
}
|
}
|
||||||
if (isExperimentalCommunityPostRemoval()) {
|
if (isExperimentalCommunityPostRemoval()) {
|
||||||
blockList.add("post_base_wrapper");
|
blockList.add("post_base_wrapper");
|
||||||
}
|
}
|
||||||
if (isExperimentalMovieUpsellRemoval()) {
|
|
||||||
blockList.add("movie_and_show_upsell_card");
|
|
||||||
}
|
|
||||||
if (isExperimentalPaidContentRemoval()) {
|
if (isExperimentalPaidContentRemoval()) {
|
||||||
blockList.add("paid_content_overlay");
|
blockList.add("paid_content_overlay");
|
||||||
}
|
}
|
||||||
@ -121,12 +145,6 @@ public class LithoAdRemoval {
|
|||||||
if (isExperimentalCommentsRemoval()) {
|
if (isExperimentalCommentsRemoval()) {
|
||||||
blockList.add("comments_composite_entry_point");
|
blockList.add("comments_composite_entry_point");
|
||||||
}
|
}
|
||||||
if (isExperimentalCompactMovieRemoval()) {
|
|
||||||
blockList.add("compact_movie");
|
|
||||||
}
|
|
||||||
if (isExperimentalHorizontalMovieShelfRemoval()) {
|
|
||||||
blockList.add("horizontal_movie_shelf");
|
|
||||||
}
|
|
||||||
if (isInFeedSurvey()) {
|
if (isInFeedSurvey()) {
|
||||||
blockList.add("in_feed_survey");
|
blockList.add("in_feed_survey");
|
||||||
}
|
}
|
||||||
@ -136,53 +154,45 @@ public class LithoAdRemoval {
|
|||||||
if (isCommunityGuidelines()) {
|
if (isCommunityGuidelines()) {
|
||||||
blockList.add("community_guidelines");
|
blockList.add("community_guidelines");
|
||||||
}
|
}
|
||||||
if (!value.contains("related_video_with_context") || indexOf(buffer.array(), endRelatedPageAd) <= 0) {
|
|
||||||
for (String s : blockList) {
|
if (containsAny(value,
|
||||||
if (value.contains(s)) {
|
"home_video_with_context",
|
||||||
if (XGlobals.debug) {
|
"related_video_with_context",
|
||||||
Log.d("TemplateBlocked", value);
|
"search_video_with_context",
|
||||||
}
|
"menu",
|
||||||
return true;
|
"root",
|
||||||
}
|
"-count",
|
||||||
}
|
"-space",
|
||||||
if (!XGlobals.debug) {
|
"-button"
|
||||||
return false;
|
)) {
|
||||||
}
|
if (XGlobals.debug) Log.d("TemplateBlocked", value);
|
||||||
if (value.contains("related_video_with_context")) {
|
return true;
|
||||||
Log.d("Template", value + " | " + bytesToHex(buffer.array()));
|
}
|
||||||
return false;
|
|
||||||
}
|
if (blockList.stream().anyMatch(value::contains)) {
|
||||||
Log.d("Template", value);
|
if (XGlobals.debug) Log.d("TemplateBlocked", value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!XGlobals.debug) return false;
|
||||||
|
if (value.contains("related_video_with_context")) {
|
||||||
|
Log.d("Template", value + " | " + bytesToHex(buffer.array()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (XGlobals.debug) {
|
Log.d("Template", value);
|
||||||
Log.d("TemplateBlocked", value);
|
return false;
|
||||||
}
|
} catch (
|
||||||
return true;
|
Exception ex) {
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.e("Template", ex.getMessage(), ex);
|
Log.e("Template", ex.getMessage(), ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int indexOf(byte[] array, byte[] target) {
|
private static boolean containsAny(String value, String... targets) {
|
||||||
if (target.length == 0) {
|
for (String string : targets)
|
||||||
return 0;
|
if (value.contains(string)) return true;
|
||||||
}
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < array.length - target.length + 1; i++) {
|
|
||||||
boolean targetFound = true;
|
|
||||||
for (int j = 0; j < target.length; j++) {
|
|
||||||
if (array[i + j] != target[j]) {
|
|
||||||
targetFound = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetFound) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String bytesToHex(byte[] bytes) {
|
private static String bytesToHex(byte[] bytes) {
|
||||||
|
@ -5,11 +5,12 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.1.3'
|
classpath 'com.android.tools.build:gradle:7.2.1'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Mon Jun 07 19:51:48 CEST 2021
|
#Mon Jun 07 19:51:48 CEST 2021
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
include ':app'
|
include ':app'
|
||||||
rootProject.name = "sb"
|
rootProject.name = "integrations"
|
Loading…
Reference in New Issue
Block a user