Update JsonInjectors.java

This commit is contained in:
Vologhat
2022-07-22 15:52:04 +03:00
parent 6f607e9ae8
commit 8a90602328
2 changed files with 83 additions and 94 deletions
@@ -12,7 +12,6 @@ import static ru.vtosters.lite.utils.Globals.getUserToken;
import static ru.vtosters.lite.utils.Newsfeed.checkCaption;
import static ru.vtosters.lite.utils.Newsfeed.checkCopyright;
import static ru.vtosters.lite.utils.Newsfeed.isBadNews;
import static ru.vtosters.lite.utils.Newsfeed.mFiltersLinks;
import static ru.vtosters.lite.utils.Preferences.ads;
import static ru.vtosters.lite.utils.Preferences.adsgroup;
import static ru.vtosters.lite.utils.Preferences.adsstories;
@@ -42,11 +41,12 @@ import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import ru.vtosters.lite.utils.Globals;
import ru.vtosters.lite.utils.Newsfeed;
public class JsonInjectors{
public class JsonInjectors {
private static final OkHttpClient mClient = new OkHttpClient();
public static JSONObject profileButton(JSONObject orig) throws JSONException{
public static JSONObject profileButton(JSONObject orig) throws JSONException {
if (haveDonateButton()) return orig;
var pic = "https://sun1-18.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png";
@@ -65,7 +65,7 @@ public class JsonInjectors{
+ text_color + decode("In0="));
}
public static JSONObject convBar(JSONObject orig) throws JSONException{
public static JSONObject convBar(JSONObject orig) throws JSONException {
var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id");
var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null
@@ -107,7 +107,7 @@ public class JsonInjectors{
+ decode("fQ=="));
}
public static JSONObject menu(JSONObject orig) throws JSONException{
public static JSONObject menu(JSONObject orig) throws JSONException {
var Special = orig.optJSONArray("special");
var Main = orig.getJSONArray("main");
var Other = orig.optJSONArray("other");
@@ -119,7 +119,7 @@ public class JsonInjectors{
return orig;
}
public static JSONObject superapp(JSONObject json) throws JSONException{
public static JSONObject superapp(JSONObject json) throws JSONException {
var superApps = Globals.getPreferences().getString("superapp_items",
"menu,promo,miniapps,vkpay_slim,greeting,holiday,weather,sport,games,informer,food,event,music,vk_run").split(",");
if (superApps.length == 0) return json;
@@ -148,7 +148,7 @@ public class JsonInjectors{
return json.putOpt("items", newItems);
}
public static JSONObject musiclink(JSONObject json){
public static JSONObject musiclink(JSONObject json) {
var oldItems = json.optJSONArray("links");
if (oldItems != null) {
@@ -161,7 +161,7 @@ public class JsonInjectors{
return json;
}
public static JSONObject onlineinfo(JSONObject json) throws ParseException, IOException, JSONException{
public static JSONObject onlineinfo(JSONObject json) throws ParseException, IOException, JSONException {
var id = json.optInt("id");
var onlineinfo = json.optJSONObject("online_info");
var time = getLastSeen(0L, id);
@@ -185,7 +185,7 @@ public class JsonInjectors{
return json;
}
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException{
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException {
if (!adsstories()) {
return json;
}
@@ -219,7 +219,7 @@ public class JsonInjectors{
return json;
}
private static void parseStoriesItem(JSONObject item) throws JSONException{
private static void parseStoriesItem(JSONObject item) throws JSONException {
var stories = item.optJSONArray("stories");
var newStories = new JSONArray();
@@ -239,41 +239,7 @@ public class JsonInjectors{
item.put("stories", newStories);
}
public static boolean parseRepostItem(JSONObject list) throws JSONException{
var item = list.optJSONArray("copy_history");
if (item == null) return false;
for (int j = 0; j < item.length(); j++) {
var items = item.optJSONObject(j);
var text = items.optString("text");
var type = items.optString("post_type");
if (isBadNews(text)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad (isBadNews), owner id " + items.optString("owner_id") + ", text: " + text);
return true;
} else if (isAds(items, type)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad (ads), owner id " + items.optString("owner_id") + ", text: " + text);
return true;
}
if (!getBoolValue("cringerepost", false)) return false;
for (String linkfilters : mFiltersLinks) {
if (text.contains(linkfilters)) {
if (dev())
Log.d("RepostFilter", "Fetched repost ad, owner id " + items.optString("owner_id") + ", text: " + text);
return true;
}
}
}
return false;
}
public static Boolean isAds(JSONObject list, String type) throws JSONException{
public static Boolean isAds(JSONObject list, String type) throws JSONException {
if (list == null || type == null || !ads()) return false;
if (list.has("ads")
@@ -299,7 +265,7 @@ public class JsonInjectors{
return false;
}
public static JSONArray newsfeedlist(JSONArray items) throws JSONException{
public static JSONArray newsfeedlist(JSONArray items) throws JSONException {
for (int j = 0; j < items.length(); j++) {
var list = items.optJSONObject(j);
var name = list.optString("id");
@@ -313,7 +279,7 @@ public class JsonInjectors{
return items;
}
public static JSONArray newsfeedadtest(JSONArray items) throws JSONException{
public static JSONArray newsfeedadtest(JSONArray items) throws JSONException {
if (!getBoolValue("newadblock", true)) return items;
var newItems = new JSONArray();
@@ -325,7 +291,11 @@ public class JsonInjectors{
continue;
}
if (authorsrecomm() && (type.equals("authors_rec") || type.startsWith("recommended_") && (type.endsWith("audios") || type.endsWith("artists") || type.endsWith("playlists") || type.endsWith("groups")))) {
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;
@@ -367,7 +337,7 @@ public class JsonInjectors{
continue;
}
if (parseRepostItem(list)) {
if (Newsfeed.injectFiltersReposts(list)) {
if (dev())
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
continue;
@@ -379,7 +349,7 @@ public class JsonInjectors{
return newItems;
}
public static JSONObject music(JSONObject json) throws JSONException{
public static JSONObject music(JSONObject json) throws JSONException {
var catalog = json.optJSONObject("catalog");
JSONArray oldItems = null;
@@ -447,7 +417,7 @@ public class JsonInjectors{
return json;
}
public static JSONObject fetchCatalogId(String section){
public static JSONObject fetchCatalogId(String section) {
if (section == null) return null;
var request = new Request.a()
@@ -473,7 +443,7 @@ public class JsonInjectors{
return null;
}
public static JSONObject friends(JSONObject json) throws JSONException{
public static JSONObject friends(JSONObject json) throws JSONException {
JSONObject catalog = json;
boolean sectionexecute = true;
boolean hasBirthday = false;
@@ -540,7 +510,7 @@ public class JsonInjectors{
}
public static boolean haveDonateButton(){
public static boolean haveDonateButton() {
int randomshower = new Random().nextInt(6);
return hasVerification() || randomshower != 1;
@@ -21,16 +21,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
import ru.vtosters.lite.hooks.JsonInjectors;
public class Newsfeed{
public class Newsfeed {
public static List<String> mFilters;
public static List<String> mFiltersLinks;
public static void setupFilters(){
public static void setupFilters() {
mFilters = new ArrayList<>();
mFiltersLinks = new ArrayList<>();
@@ -40,22 +39,22 @@ public class Newsfeed{
getFilter("shitposting", "IDontWantToReadIt.txt", mFilters);
getFilter("cringecopyright", "CopyrightAds.txt", mFiltersLinks);
var customfilters = getPrefsValue("spamfilters");
if (!customfilters.isEmpty()) {
mFilters.addAll(Arrays.asList(customfilters.split(", ")));
var customFilters = getPrefsValue("spamfilters");
if (!customFilters.isEmpty()) {
mFilters.addAll(Arrays.asList(customFilters.split(", ")));
}
var linkfilter = getPrefsValue("linkfilter");
if (!linkfilter.isEmpty()) {
mFiltersLinks.addAll(Arrays.asList(linkfilter.split(", ")));
var linkFilter = getPrefsValue("linkfilter");
if (!linkFilter.isEmpty()) {
mFiltersLinks.addAll(Arrays.asList(linkFilter.split(", ")));
}
}
public static void getFilter(String boolname, String filename, List<String> list){
public static void getFilter(String boolname, String filename, List<String> list) {
if (getBoolValue(boolname, true)) {
try {
var scanner = new Scanner(getContext().getAssets().open(filename));
while(scanner.hasNextLine()) {
while (scanner.hasNextLine()) {
var line = scanner.nextLine();
if (!line.isEmpty())
list.add(line.toLowerCase());
@@ -66,22 +65,27 @@ public class Newsfeed{
}
} // Get needed filter list from assets
public static boolean injectFiltersReposts(JSONObject obj) throws JSONException{
public static boolean injectFiltersReposts(JSONObject obj) throws JSONException {
if (getBoolValue("cringerepost", false) && obj.has("copy_history")) {
return JsonInjectors.parseRepostItem(obj);
}
return false;
}
var copyHistoryNode = obj.optJSONArray("copy_history");
for (int i = 0; i < copyHistoryNode.length(); i++) {
var item = copyHistoryNode.optJSONObject(i);
var text = item.optString("text");
public static boolean checkCopyright(JSONObject json) throws JSONException{
if (json.has("copyright")) {
if (copyright_post()) return true;
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;
}
var copyright = json.optJSONObject("copyright");
if (copyright != null) {
var copyrightlink = copyright.getString("link").toLowerCase();
for (String linkfilters : mFiltersLinks) {
if (copyrightlink.contains(linkfilters)) {
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;
}
}
@@ -90,23 +94,38 @@ public class Newsfeed{
return false;
}
public static boolean isRecomsGroup(String src){
public static boolean checkCopyright(JSONObject json) throws JSONException {
if (json.has("copyright")) {
if (copyright_post()) return true;
var copyright = json.optJSONObject("copyright");
var copyrightLink = copyright.getString("link").toLowerCase();
for (String filter : mFiltersLinks) {
if (copyrightLink.contains(filter)) {
return true;
}
}
}
return false;
}
public static boolean isRecomsGroup(String src) {
return authorsrecomm() && src.equals("recommended_groups");
}
public static boolean isMusicBlock(String src){
public static boolean isMusicBlock(String src) {
return authorsrecomm() && (src.equals("recommended_audios") || src.equals("recommended_artists") || src.equals("recommended_playlists"));
}
public static boolean isNewsBlock(String src){
public static boolean isNewsBlock(String src) {
return ads() && src.equals("tags_suggestions");
}
public static String getAllFilters(){
public static String getAllFilters() {
return getPrefsValue("spamfilters");
}
public static boolean isBadNews(String text){
public static boolean isBadNews(String text) {
var textInLowerCase = text.toLowerCase();
for (String filter : mFilters) {
if (textInLowerCase.contains(filter)) {
@@ -118,50 +137,50 @@ public class Newsfeed{
return false;
}
public static boolean checkCaption(JSONObject postJson){
try {
public static boolean checkCaption(JSONObject postJson) {
if (postJson.has("caption")) {
if (captions()) return true;
var caption = postJson.optJSONObject("caption");
if (caption != null) {
if (captions()) return true;
if (postsrecomm()) {
if (postsrecomm()) {
try {
var 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");
}
}
} catch (JSONException e) {
Log.d("checkCaption", "Caption error");
}
return false;
}
public static boolean isAds(String optString){
public static boolean isAds(String optString) {
return ads() && (optString.equals("ads_easy_promote") ||
optString.equals("promo_button") ||
optString.equals("app_widget") ||
optString.equals("ads"));
}
public static boolean isAuthorRecommendations(String optString){
public static boolean isAuthorRecommendations(String optString) {
return authorsrecomm() && optString.equals("authors_rec");
}
public static boolean isPostRecommendations(String optString){
public static boolean isPostRecommendations(String optString) {
return postsrecomm() && (optString.equals("live_recommended") ||
optString.equals("inline_user_rec"));
}
public static boolean isFriendsRecommendations(String optString){
public static boolean isFriendsRecommendations(String optString) {
return friendsrecomm() && (optString.equals("user_rec") ||
optString.equals("friends_recommendations") ||
optString.equals("friends_recomm"));
}
public static boolean isGroupAds(JSONObject obj){
public static boolean isGroupAds(JSONObject obj) {
return adsgroup() && obj.optInt("marked_as_ads", 0) == 1;
}
}