some adblock refactoring

This commit is contained in:
gdlbo
2022-09-03 23:18:12 +03:00
parent 0698985623
commit b746594b1d
13 changed files with 418 additions and 364 deletions
@@ -0,0 +1,351 @@
package ru.vtosters.lite.hooks;
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCaption;
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCopyright;
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isBadNews;
import static ru.vtosters.lite.utils.Preferences.ads;
import static ru.vtosters.lite.utils.Preferences.adsgroup;
import static ru.vtosters.lite.utils.Preferences.adsstories;
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
import static ru.vtosters.lite.utils.Preferences.dev;
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Collections;
import java.util.LinkedHashSet;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
public class AdBlockHook{
public static Boolean discoverAdBlock(JSONObject jsonObject){
if (jsonObject == null) return true;
try {
var type = jsonObject.optString("type");
var post = jsonObject.optJSONObject("post");
if (jsonObject.optString("template").contains("ads") || jsonObject.has("ads")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: ads");
return false;
}
if (isAds(post, type)) {
return false;
}
if (authorsrecomm() && (type.equals("authors_rec")
|| type.startsWith("recommended_") && (type.endsWith("audios")
|| type.endsWith("artists")
|| type.endsWith("playlists")
|| type.endsWith("groups")))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: authorsrecomm");
return false;
}
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: postsrecomm");
return false;
}
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: friendsrecomm");
return false;
}
if (adsgroup() && (post != null ? post.optInt("marked_as_ads") : 0) == 1 && !isWhitelistedAd(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: marked_as_ads is true");
return false;
}
if (post != null && isBadNews(post.optString("text")) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: text filters");
return false;
}
if (post != null && checkCopyright(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: copyright filters");
return false;
}
if (post != null && checkCaption(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: caption filters");
return false;
}
if (post != null && NewsFeedFiltersUtils.injectFiltersReposts(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: repost ad");
return false;
}
} catch (Exception e) {
Log.d("NewsfeedAdBlockV2", "discover: " + e.getMessage());
}
return true;
}
public static JSONObject discoverInject(JSONObject json) throws JSONException{
var items = json.optJSONArray("items");
var newObj = new JSONArray();
// newObj.put(discoverObj()); // template injection
for (int i = 0; i < (items != null ? items.length() : 0); i++) {
try {
var curr = items.getJSONObject(i);
if (!curr.optString("template").contains("info") && discoverAdBlock(curr)) {
newObj.put(items.optJSONObject(i));
}
} catch (Exception e) {
Log.d("NewsfeedAdBlockV2", "discover: " + e);
}
}
json.put("items", newObj);
return json;
}
public static JSONObject discoverObj() throws JSONException{
var mainjson = new JSONObject();
var info = new JSONObject();
info.put("title", "Test Injection");
info.put("text_color", "#ffffff");
info.put("description", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat");
var image = new JSONArray();
var imageQuality1 = new JSONObject();
imageQuality1.put("url", "https://w7.pngwing.com/pngs/505/1021/png-transparent-konata-izumi-lucky-star-desktop-anime-anime-blue-mammal-face.png");
imageQuality1.put("width", 72); // 72, 108, 144, 216, 288
imageQuality1.put("height", 72); // 72, 108, 144, 216, 288
image.put(imageQuality1);
var background = new JSONArray();
var backgroundQuality1 = new JSONObject();
backgroundQuality1.put("url", "https://2ch.life/vg/arch/2022-08-22/src/38524739/16440606579870.jpg");
backgroundQuality1.put("width", 344); // 344, 516, 680, 1032, 1376
backgroundQuality1.put("height", 215); // 215, 323, 426, 645, 860
background.put(backgroundQuality1);
info.put("image", image);
info.put("background", background);
mainjson.put("info", info);
mainjson.put("track_code", "info_banner_donut_catalog");
mainjson.put("template", "info");
var action = new JSONObject();
action.put("type", "open_url");
action.put("url", "vk.com/vtosters_official");
action.put("target", "internal");
mainjson.put("action", action);
return mainjson;
}
public static JSONArray feedInject(JSONArray items){
if (items.length() == 0) return items;
try {
var newItems = new JSONArray();
for (int j = 0; j < items.length(); j++) {
var list = items.optJSONObject(j);
if (list == null) continue;
var type = list.optString("type");
if (isAds(list, type)) {
continue;
}
if (authorsrecomm() && (type.equals("authors_rec")
|| type.startsWith("recommended_") && (type.endsWith("audios")
|| type.endsWith("artists")
|| type.endsWith("playlists")
|| type.endsWith("groups")))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: authorsrecomm");
continue;
}
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: postsrecomm");
continue;
}
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: friendsrecomm");
continue;
}
if (adsgroup() && list.optInt("marked_as_ads") == 1 && !isWhitelistedAd(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: marked_as_ads is true");
continue;
}
if (isBadNews(list.optString("text")) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: text filters");
continue;
}
if (checkCopyright(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: copyright filters");
continue;
}
if (checkCaption(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: caption filters");
continue;
}
if (NewsFeedFiltersUtils.injectFiltersReposts(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
continue;
}
newItems.put(list);
}
return newItems;
} catch (Exception e) {
Log.d("NewsfeedAdBlockV2", e.getMessage());
}
return items;
}
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException{
if (!adsstories()) {
return json;
}
if (json.has("ads")) {
var ad = json.optJSONObject("ads");
if (isDeleteFix) {
if (ad != null) {
ad.optJSONObject("settings")
.put("stories_interval", 0)
.put("authors_interval", 0)
.put("time_interval", 0)
.put("stories_init", 0)
.put("authors_init", 0)
.put("time_init", 0);
}
if (dev()) Log.d("StoriesAds", "Set ads settings at zero values");
} else {
json.remove("ads");
if (dev()) Log.d("StoriesAds", "Removed ads block");
}
}
if (!json.has("items")) return json;
var items = json.optJSONArray("items");
if (items != null) {
for (int i = 0; i < items.length(); i++) {
var item = items.optJSONObject(i);
if (item != null) {
parseStoriesItem(item);
}
}
}
return json;
}
private static void parseStoriesItem(JSONObject item) throws JSONException{
var stories = item.optJSONArray("stories");
var newStories = new JSONArray();
if (stories == null) return;
for (int j = 0; j < stories.length(); j++) {
var story = stories.optJSONObject(j);
if (!story.optBoolean("is_ads") && !story.optBoolean("is_promo")) {
newStories.put(story);
} else {
if (dev())
Log.d("StoriesAds", "Fetched ad, owner id " + story.optString("owner_id") + ", caption " + story.optString("caption"));
}
}
item.put("stories", newStories);
}
public static Boolean isAds(JSONObject list, String type) throws JSONException{
if (list == null || type == null || !ads()) return false;
if (list.has("ads")
|| type.equals("ads")
|| type.equals("carousel")
|| type.equals("html5_ad")
|| type.equals("ads_easy_promote")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: ads");
return true;
}
if (type.equals("promo_button")
|| type.equals("app_widget")
|| type.equals("app_video")
|| type.equals("app_slider")
|| type.equals("tags_suggestions")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: promo");
return true;
}
return false;
}
public static Boolean isWhitelistedFilters(JSONObject list){
var id = String.valueOf(list.optInt("owner_id"));
if (id.equals("0")) {
id = String.valueOf(list.optInt("source_id"));
}
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_filters_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
return whitelist.contains(id);
}
public static Boolean isWhitelistedAd(JSONObject list){
var id = String.valueOf(list.optInt("owner_id"));
if (id.equals("0")) {
id = String.valueOf(list.optInt("source_id"));
}
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_ad_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
return whitelist.contains(id);
}
}
@@ -204,138 +204,6 @@ public class JsonInjectors {
return json;
}
public static Boolean discoverAdBlock(JSONObject jsonObject) throws JSONException {
if (jsonObject == null) return true;
try {
var type = jsonObject.optString("type");
var post = jsonObject.optJSONObject("post");
if (jsonObject.optString("template").contains("ads") || jsonObject.has("ads")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: ads");
return false;
}
if (isAds(post, type)) {
return false;
}
if (authorsrecomm() && (type.equals("authors_rec")
|| type.startsWith("recommended_") && (type.endsWith("audios")
|| type.endsWith("artists")
|| type.endsWith("playlists")
|| type.endsWith("groups")))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: authorsrecomm");
return false;
}
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: postsrecomm");
return false;
}
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: friendsrecomm");
return false;
}
if (adsgroup() && (post != null ? post.optInt("marked_as_ads") : 0) == 1 && !isWhitelistedAd(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: marked_as_ads is true");
return false;
}
if (post != null && isBadNews(post.optString("text")) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: text filters");
return false;
}
if (post != null && checkCopyright(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: copyright filters");
return false;
}
if (post != null && checkCaption(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: caption filters");
return false;
}
if (post != null && NewsFeedFiltersUtils.injectFiltersReposts(post) && !isWhitelistedFilters(post)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: repost ad");
return false;
}
} catch (Exception e) {
Log.d("NewsfeedAdBlockV2", "discover: " + e.getMessage());
}
return true;
}
public static JSONObject discoverInject(JSONObject json) throws JSONException{
var items = json.optJSONArray("items");
var newObj = new JSONArray();
// newObj.put(discoverObj()); // template injection
for (int i = 0; i < (items != null ? items.length() : 0); i++) {
var curr = items.getJSONObject(i);
if (!curr.optString("template").contains("info") && discoverAdBlock(curr)){
newObj.put(items.optJSONObject(i));
}
}
json.put("items", newObj);
return json;
}
public static JSONObject discoverObj() throws JSONException{
var mainjson = new JSONObject();
var info = new JSONObject();
info.put("title", "Test Injection");
info.put("text_color", "#ffffff");
info.put("description", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat");
var image = new JSONArray();
var imageQuality1 = new JSONObject();
imageQuality1.put("url", "https://w7.pngwing.com/pngs/505/1021/png-transparent-konata-izumi-lucky-star-desktop-anime-anime-blue-mammal-face.png");
imageQuality1.put("width", 72); // 72, 108, 144, 216, 288
imageQuality1.put("height", 72); // 72, 108, 144, 216, 288
image.put(imageQuality1);
var background = new JSONArray();
var backgroundQuality1 = new JSONObject();
backgroundQuality1.put("url", "https://2ch.life/vg/arch/2022-08-22/src/38524739/16440606579870.jpg");
backgroundQuality1.put("width", 344); // 344, 516, 680, 1032, 1376
backgroundQuality1.put("height", 215); // 215, 323, 426, 645, 860
background.put(backgroundQuality1);
info.put("image", image);
info.put("background", background);
mainjson.put("info", info);
mainjson.put("track_code", "info_banner_donut_catalog");
mainjson.put("template", "info");
var action = new JSONObject();
action.put("type", "open_url");
action.put("url", "vk.com/vtosters_official");
action.put("target", "internal");
mainjson.put("action", action);
return mainjson;
}
public static JSONObject menu(JSONObject orig) throws JSONException {
var Special = orig.optJSONArray("special");
var Main = orig.getJSONArray("main");
@@ -486,113 +354,6 @@ public class JsonInjectors {
return profiles;
}
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException {
if (!adsstories()) {
return json;
}
if (json.has("ads")) {
if (isDeleteFix) {
json.optJSONObject("ads").optJSONObject("settings")
.put("stories_interval", 0)
.put("authors_interval", 0)
.put("time_interval", 0)
.put("stories_init", 0)
.put("authors_init", 0)
.put("time_init", 0);
if (dev()) Log.d("StoriesAds", "Set ads settings at zero values");
} else {
json.remove("ads");
if (dev()) Log.d("StoriesAds", "Removed ads block");
}
}
if (!json.has("items")) return json;
var items = json.optJSONArray("items");
if (items != null) {
for (int i = 0; i < items.length(); i++) {
var item = items.optJSONObject(i);
if (item != null) {
parseStoriesItem(item);
}
}
}
return json;
}
private static void parseStoriesItem(JSONObject item) throws JSONException {
var stories = item.optJSONArray("stories");
var newStories = new JSONArray();
if (stories == null) return;
for (int j = 0; j < stories.length(); j++) {
var story = stories.optJSONObject(j);
if (!story.optBoolean("is_ads") && !story.optBoolean("is_promo")) {
newStories.put(story);
} else {
if (dev())
Log.d("StoriesAds", "Fetched ad, owner id " + story.optString("owner_id") + ", caption " + story.optString("caption"));
}
}
item.put("stories", newStories);
}
public static Boolean isAds(JSONObject list, String type) throws JSONException {
if (list == null || type == null || !ads()) return false;
if (list.has("ads")
|| type.equals("ads")
|| type.equals("carousel")
|| type.equals("html5_ad")
|| type.equals("ads_easy_promote")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: ads");
return true;
}
if (type.equals("promo_button")
|| type.equals("app_widget")
|| type.equals("app_video")
|| type.equals("app_slider")
|| type.equals("tags_suggestions")) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: promo");
return true;
}
return false;
}
public static Boolean isWhitelistedFilters(JSONObject list){
var id = String.valueOf(list.optInt("owner_id"));
if (id.equals("0")) {
id = String.valueOf(list.optInt("source_id"));
}
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_filters_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
return whitelist.contains(id);
}
public static Boolean isWhitelistedAd(JSONObject list){
var id = String.valueOf(list.optInt("owner_id"));
if (id.equals("0")) {
id = String.valueOf(list.optInt("source_id"));
}
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_ad_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
return whitelist.contains(id);
}
public static JSONArray newsfeedlist(JSONArray items) throws JSONException {
var selectedItems = getDefaultPrefs().getString("news_feed_selected_items", "");
var filtersSet = getDefaultPrefs().getStringSet("news_feed_items_set", null);
@@ -630,84 +391,6 @@ public class JsonInjectors {
return items;
}
public static JSONArray newsfeedadtest(JSONArray items) throws JSONException {
try {
var newItems = new JSONArray();
for (int j = 0; j < items.length(); j++) {
var list = items.optJSONObject(j);
if (list == null) continue;
var type = list.optString("type");
if (isAds(list, type)) {
continue;
}
if (authorsrecomm() && (type.equals("authors_rec")
|| type.startsWith("recommended_") && (type.endsWith("audios")
|| type.endsWith("artists")
|| type.endsWith("playlists")
|| type.endsWith("groups")))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: authorsrecomm");
continue;
}
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: postsrecomm");
continue;
}
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: friendsrecomm");
continue;
}
if (adsgroup() && list.optInt("marked_as_ads") == 1 && !isWhitelistedAd(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: marked_as_ads is true");
continue;
}
if (isBadNews(list.optString("text")) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: text filters");
continue;
}
if (checkCopyright(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: copyright filters");
continue;
}
if (checkCaption(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: caption filters");
continue;
}
if (NewsFeedFiltersUtils.injectFiltersReposts(list) && !isWhitelistedFilters(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
continue;
}
newItems.put(list);
}
return newItems;
} catch (Exception e) {
Log.d("NewsfeedAdBlockV2", e.getMessage());
}
return items;
}
public static JSONObject music(JSONObject json) throws JSONException {
var catalog = json.optJSONObject("catalog");
@@ -905,7 +588,6 @@ public class JsonInjectors {
return json;
}
public static boolean haveDonateButton() {
int randomshower = new Random().nextInt(6);
@@ -23,7 +23,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import ru.vtosters.lite.hooks.JsonInjectors;
import ru.vtosters.lite.hooks.AdBlockHook;
public class NewsFeedFiltersUtils {
public static List<String> mFilters;
@@ -58,16 +58,22 @@ public class NewsFeedFiltersUtils {
}
public static void getFilter(String boolname, String filename, List<String> list) {
var ctx = getGlobalContext();
if (getBoolValue(boolname, false)) {
try {
var scanner = new Scanner(getGlobalContext().getAssets().open(filename));
while (scanner.hasNextLine()) {
var line = scanner.nextLine();
if (!line.isEmpty())
list.add(line.toLowerCase());
Scanner scanner;
if (ctx != null) {
scanner = new Scanner(ctx.getAssets().open(filename));
while (scanner.hasNextLine()) {
var line = scanner.nextLine();
if (!line.isEmpty())
list.add(line.toLowerCase());
}
}
} catch (IOException e) {
e.printStackTrace();
Log.d("NewsFeedFiltersUtils", e.getMessage());
}
}
} // Get needed filter list from assets
@@ -75,25 +81,27 @@ public class NewsFeedFiltersUtils {
public static boolean injectFiltersReposts(JSONObject obj) throws JSONException {
if (getBoolValue("cringerepost", false) && obj.has("copy_history")) {
var copyHistoryNode = obj.optJSONArray("copy_history");
for (int i = 0; i < copyHistoryNode.length(); i++) {
var item = copyHistoryNode.optJSONObject(i);
var text = item.optString("text");
if (copyHistoryNode != null) {
for (int i = 0; i < copyHistoryNode.length(); i++) {
var item = copyHistoryNode.optJSONObject(i);
var text = item.optString("text");
if (isBadNews(text)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad (isBadNews), owner id " + item.optString("owner_id") + ", text: " + text);
return true;
} else if (JsonInjectors.isAds(item, item.optString("post_type"))) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad (ads), owner id " + item.optString("owner_id") + ", text: " + text);
return true;
}
for (String filter : mFiltersLinks) {
if (text.contains(filter)) {
if (isBadNews(text)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad, owner id " + item.optString("owner_id") + ", text: " + text);
Log.d("RepostFilter", "Fetched repost ad (isBadNews), owner id " + item.optString("owner_id") + ", text: " + text);
return true;
} else if (AdBlockHook.isAds(item, item.optString("post_type"))) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad (ads), owner id " + item.optString("owner_id") + ", text: " + text);
return true;
}
for (String filter : mFiltersLinks) {
if (text.contains(filter)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad, owner id " + item.optString("owner_id") + ", text: " + text);
return true;
}
}
}
}
@@ -106,15 +114,25 @@ public class NewsFeedFiltersUtils {
if (copyright_post()) return true;
var copyright = json.optJSONObject("copyright");
var copyrightName = copyright.getString("name").toLowerCase();
var copyrightLink = copyright.getString("link").toLowerCase();
String copyrightName = null;
if (copyright != null) {
copyrightName = copyright.getString("name").toLowerCase();
}
String copyrightLink = null;
if (copyright != null) {
copyrightLink = copyright.getString("link").toLowerCase();
}
for (String filter : mFiltersNames) {
if (copyrightName.contains(filter)) return true;
if (copyrightName != null && copyrightName.contains(filter)) return true;
}
for (String filter : mFiltersLinks) {
if (copyrightLink.contains(filter)) return true;
if (copyrightLink != null && copyrightLink.contains(filter)) return true;
}
}
return false;
@@ -154,12 +172,15 @@ public class NewsFeedFiltersUtils {
var caption = postJson.optJSONObject("caption");
if (postsrecomm()) {
try {
var type = caption.getString("type");
return type.equals("explorebait") || // Может быть интересно
type.equals("shared") || // Поделился записью
type.equals("digest") || // Рекомедации
type.equals("commented") || // Комментирует
type.equals("voted"); // Проголосовал в опросе
String type;
if (caption != null) {
type = caption.getString("type");
return type.equals("explorebait") || // Может быть интересно
type.equals("shared") || // Поделился записью
type.equals("digest") || // Рекомедации
type.equals("commented") || // Комментирует
type.equals("voted"); // Проголосовал в опросе
}
} catch (JSONException e) {
Log.d("checkCaption", "Caption error");
}