Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Remove story/ clear comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kmod-midori committed Jul 30, 2017
1 parent 7dfcf22 commit c9d4528
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
53 changes: 50 additions & 3 deletions app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,6 +37,7 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage {
private val disabled_feature = arrayListOf<String>()
private var content_keyword = listOf<String>()
private var user_keyword = listOf<String>()
private var comment_filters = listOf<Int>()


override fun handleInitPackageResources(resparam: InitPackageResourcesParam) {
Expand Down Expand Up @@ -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<Any>()
}
})
}

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")
Expand All @@ -268,6 +301,11 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage {

hookMoreItems(lpparam)

if (prefs.getBoolean("no_story", false)){
hookStory(lpparam)
}

hookComment(lpparam)
}

private fun reloadPrefs() : Boolean {
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="comment_filters">
<item>我转发过的微博</item>
<item>博主发表的评论</item>
<item>博主回复的评论</item>
<item>博主赞过的评论</item>
</string-array>
<string-array name="comment_filters_values">
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<string name="pref_title_force_browser">强制使用外置浏览器</string>
<string name="pref_description_force_browser">与“去你大爷的内置浏览器”可能发生冲突,请禁用该模块的“微博”规则。</string>
<string name="pref_title_disable_new_message_flow">禁用新版通知界面</string>
<string name="pref_title_no_story">禁用首页上的“微博故事”推荐</string>
<string name="pref_title_comment_filters">评论界面过滤</string>

<string name="pref_filtering_title">屏蔽(每行一个)</string>
<string name="pref_title_content_keyword">内容关键字</string>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
android:key="disable_new_message_flow"
android:title="@string/pref_title_disable_new_message_flow"/>

<SwitchPreference
android:defaultValue="false"
android:key="no_story"
android:title="@string/pref_title_no_story"/>

<MultiSelectListPreference
android:key="comment_filters"
android:title="@string/pref_title_comment_filters"
android:entries="@array/comment_filters"
android:entryValues="@array/comment_filters_values"
android:defaultValue="@array/comment_filters_values" />

<SwitchPreference
android:defaultValue="false"
android:key="debug_mode"
Expand Down

0 comments on commit c9d4528

Please sign in to comment.