From c9d4528d5b5127fb76031067c64e3e899132bb80 Mon Sep 17 00:00:00 2001 From: chengyuhui Date: Sun, 30 Jul 2017 12:40:38 +0800 Subject: [PATCH] Remove story/ clear comments --- app/build.gradle | 4 +- .../kotlin/moe/reimu/weiboxposed/Module.kt | 53 +++++++++++++++++-- app/src/main/res/values/arrays.xml | 15 ++++++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_general.xml | 12 +++++ 5 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/values/arrays.xml diff --git a/app/build.gradle b/app/build.gradle index 819fcde..31ff9b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "moe.reimu.weiboxposed" minSdkVersion 17 targetSdkVersion 26 - versionCode 15 - versionName "1.6.1" + versionCode 16 + versionName "1.7" } buildTypes { release { diff --git a/app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt b/app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt index 6d406c6..ed76b77 100644 --- a/app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt +++ b/app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt @@ -23,9 +23,7 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResou import de.robv.android.xposed.callbacks.XC_LoadPackage import de.robv.android.xposed.XposedBridge.hookAllMethods -import de.robv.android.xposed.XposedHelpers.findAndHookMethod -import de.robv.android.xposed.XposedHelpers.findClass -import de.robv.android.xposed.XposedHelpers.getObjectField +import de.robv.android.xposed.XposedHelpers.* class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage { companion object { @@ -39,6 +37,7 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage { private val disabled_feature = arrayListOf() private var content_keyword = listOf() private var user_keyword = listOf() + private var comment_filters = listOf() override fun handleInitPackageResources(resparam: InitPackageResourcesParam) { @@ -254,6 +253,40 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage { }) } + fun hookStory(lpparam: XC_LoadPackage.LoadPackageParam) { + findAndHookMethod("$WB_PACKAGE_NAME.story.common.bean.wrapper.StoryListWrapper", + lpparam.classLoader, + "toList", + object : XC_MethodHook() { + override fun beforeHookedMethod(param: XC_MethodHook.MethodHookParam) { + param.result = arrayListOf() + } + }) + } + + fun hookComment(lpparam: XC_LoadPackage.LoadPackageParam) { + findAndHookMethod("$WB_PACKAGE_NAME.models.JsonCommentMessageList", + lpparam.classLoader, + "getCommentMessageList", + object : XC_MethodHook() { + override fun afterHookedMethod(param: XC_MethodHook.MethodHookParam) { + val origResult = param.result as ArrayList<*> + val iterator = origResult.iterator() + while (iterator.hasNext()) { + val comment = iterator.next() + try { + val comment_type = getObjectField(comment, "comment_type_new") as Int + if (comment_filters.contains(comment_type)) { + logd("Comment type = $comment_type, removed.") + iterator.remove() + } + } catch (e: NoSuchFieldError) {} + } + + } + }) + } + private fun hookWeibo(lpparam: XC_LoadPackage.LoadPackageParam) { if (!reloadPrefs()){ log("Module disabled") @@ -268,6 +301,11 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage { hookMoreItems(lpparam) + if (prefs.getBoolean("no_story", false)){ + hookStory(lpparam) + } + + hookComment(lpparam) } private fun reloadPrefs() : Boolean { @@ -295,6 +333,15 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage { user_keyword = prefs.getString("user_keyword", "").split("\n") user_keyword = user_keyword.filter(String::isNotBlank) + + // 3 -> WBCommmonCommentTypeForwardedByMe + // 4 -> WBCommmonCommentTypeCommmentedByBlogger + // 5 -> WBCommmonCommentTypeReplyByBlogger + // 6 -> WBCommmonCommentTypeLikedByBlogger + comment_filters = prefs.getStringSet("comment_filters", setOf("3", "4", "5", "6")).map { + it.toInt() + } + log("loaded") return true } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..1ba31d0 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,15 @@ + + + + 我转发过的微博 + 博主发表的评论 + 博主回复的评论 + 博主赞过的评论 + + + 3 + 4 + 5 + 6 + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 607b5d1..7b81d26 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,8 @@ 强制使用外置浏览器 与“去你大爷的内置浏览器”可能发生冲突,请禁用该模块的“微博”规则。 禁用新版通知界面 + 禁用首页上的“微博故事”推荐 + 评论界面过滤 屏蔽(每行一个) 内容关键字 diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 938abf6..f6ad2d7 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -26,6 +26,18 @@ android:key="disable_new_message_flow" android:title="@string/pref_title_disable_new_message_flow"/> + + + +