From 3ef61ee35fb0a57ab54698999014e168019a4db3 Mon Sep 17 00:00:00 2001 From: mkx173 Date: Tue, 26 Mar 2024 01:46:31 -0700 Subject: [PATCH] feat: remove video from personalized feed --- app/build.gradle | 2 +- .../java/gm/tieba/tabswitch/XposedInit.java | 4 ++- .../tieba/tabswitch/hooker/TSPreference.java | 24 ++++++++++++--- .../hooker/eliminate/PurgeVideo.java | 30 +++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/gm/tieba/tabswitch/hooker/eliminate/PurgeVideo.java diff --git a/app/build.gradle b/app/build.gradle index 3579a02a..b74aa8fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { targetSdk sdk versionCode gitCommitCount versionName '2.9.6' - buildConfigField "String", "TARGET_VERSION", "\"12.57.0.1\"" + buildConfigField "String", "TARGET_VERSION", "\"12.57.5.0\"" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' externalNativeBuild { diff --git a/app/src/main/java/gm/tieba/tabswitch/XposedInit.java b/app/src/main/java/gm/tieba/tabswitch/XposedInit.java index 24208703..7ef4d289 100644 --- a/app/src/main/java/gm/tieba/tabswitch/XposedInit.java +++ b/app/src/main/java/gm/tieba/tabswitch/XposedInit.java @@ -51,6 +51,7 @@ import gm.tieba.tabswitch.hooker.eliminate.Purge; import gm.tieba.tabswitch.hooker.eliminate.PurgeEnter; import gm.tieba.tabswitch.hooker.eliminate.PurgeMy; +import gm.tieba.tabswitch.hooker.eliminate.PurgeVideo; import gm.tieba.tabswitch.hooker.eliminate.RedTip; import gm.tieba.tabswitch.hooker.eliminate.RemoveUpdate; import gm.tieba.tabswitch.hooker.extra.ForbidGesture; @@ -152,7 +153,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { new RemoveUpdate(), new FoldTopCardView(), new MsgCenterTab(), - new NotificationDetect() + new NotificationDetect(), + new PurgeVideo() ); final var matchers = new ArrayList(hookers.size() + 2); matchers.add(new TbDialog()); diff --git a/app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java b/app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java index 7bd8b667..e7ec790a 100644 --- a/app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java +++ b/app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java @@ -190,9 +190,8 @@ private LinearLayout createRootPreference(final Activity activity) { preferenceLayout.addView(new SwitchButtonHolder(activity, "净化进吧", "purge_enter", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "净化我的", "purge_my", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "净化置顶帖", "fold_top_card_view", SwitchButtonHolder.TYPE_SWITCH)); - preferenceLayout.addView(new SwitchButtonHolder(activity, "隐藏小红点", "red_tip", SwitchButtonHolder.TYPE_SWITCH)); - preferenceLayout.addView(new SwitchButtonHolder(activity, "禁用更新提示", "remove_update", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "只推荐已关注的吧", "follow_filter", SwitchButtonHolder.TYPE_SWITCH)); + preferenceLayout.addView(new SwitchButtonHolder(activity, "屏蔽首页视频贴", "purge_video", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "过滤首页推荐", "personalized_filter", SwitchButtonHolder.TYPE_DIALOG)); preferenceLayout.addView(new SwitchButtonHolder(activity, "过滤帖子回复", "content_filter", SwitchButtonHolder.TYPE_DIALOG)); preferenceLayout.addView(new SwitchButtonHolder(activity, "过滤吧页面", "frs_page_filter", SwitchButtonHolder.TYPE_DIALOG)); @@ -237,6 +236,8 @@ private LinearLayout createRootPreference(final Activity activity) { preferenceLayout.addView(originSrcOnlyWifiButton); preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "奇怪怪" : "其它")); + preferenceLayout.addView(new SwitchButtonHolder(activity, "隐藏小红点", "red_tip", SwitchButtonHolder.TYPE_SWITCH)); + preferenceLayout.addView(new SwitchButtonHolder(activity, "禁用更新提示", "remove_update", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "禁用帖子手势", "forbid_gesture", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "用赞踩差数代替赞数", "agree_num", SwitchButtonHolder.TYPE_SWITCH)); preferenceLayout.addView(new SwitchButtonHolder(activity, "禁止检测通知开启状态", "notification_detect", SwitchButtonHolder.TYPE_SWITCH)); @@ -269,10 +270,10 @@ private LinearLayout createRootPreference(final Activity activity) { intent.setData(Uri.parse("https://t.me/TabSwitch")); activity.startActivity(intent); })); - preferenceLayout.addView(TSPreferenceHelper.createButton("版本(适配版本)", String.format(Locale.CHINA, "%s_%d (%s)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, BuildConfig.TARGET_VERSION), true, v -> { + preferenceLayout.addView(TSPreferenceHelper.createButton("版本", String.format(Locale.CHINA, "%s_%d (%s)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, abbreviateVersion(BuildConfig.TARGET_VERSION)), true, v -> { final Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); - intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS/actions")); + intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS/releases")); activity.startActivity(intent); })); return preferenceLayout; @@ -307,4 +308,19 @@ private LinearLayout createHidePreference(final Activity activity) { TraceChecker.sChildCount = preferenceLayout.getChildCount(); return preferenceLayout; } + + private static String abbreviateVersion(String version) { + // Split the version string by dot (.) + String[] parts = version.split("\\."); + + // Check if there are at least two version codes + if (parts.length >= 2) { + // Concatenate the first two version codes + return parts[0] + parts[1]; + } else { + // If there are less than two version codes, return the original string + return version; + } + } + } diff --git a/app/src/main/java/gm/tieba/tabswitch/hooker/eliminate/PurgeVideo.java b/app/src/main/java/gm/tieba/tabswitch/hooker/eliminate/PurgeVideo.java new file mode 100644 index 00000000..fc0fb3e4 --- /dev/null +++ b/app/src/main/java/gm/tieba/tabswitch/hooker/eliminate/PurgeVideo.java @@ -0,0 +1,30 @@ +package gm.tieba.tabswitch.hooker.eliminate; + +import androidx.annotation.NonNull; + +import java.util.List; + +import de.robv.android.xposed.XC_MethodHook; +import de.robv.android.xposed.XposedHelpers; +import gm.tieba.tabswitch.XposedContext; +import gm.tieba.tabswitch.hooker.IHooker; + +public class PurgeVideo extends XposedContext implements IHooker { + @NonNull + @Override + public String key() { + return "purge_video"; + } + + @Override + public void hook() throws Throwable { + XposedHelpers.findAndHookMethod("tbclient.Personalized.DataRes$Builder", sClassLoader, "build", boolean.class, new XC_MethodHook() { + @Override + protected void beforeHookedMethod(final MethodHookParam param) throws Throwable { + final List threadList = (List) XposedHelpers.getObjectField(param.thisObject, "thread_list"); + if (threadList == null) return; + threadList.removeIf(o -> XposedHelpers.getObjectField(o, "video_info") != null); + } + }); + } +}