Skip to content

Commit

Permalink
feat: search filter add remove relate promote (yujincheng08#1567)
Browse files Browse the repository at this point in the history
搜索过滤器新增移除推广(例如起飞推广)
  • Loading branch information
CodePwn2021 authored Nov 18, 2024
1 parent 0d39ff1 commit 233a877
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/me/iacn/biliroaming/SearchFilterDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class SearchFilterDialog(activity: Activity, prefs: SharedPreferences) :
uidGroup.addView(keywordInputItem(uidGroup, it, EditorInfo.TYPE_CLASS_NUMBER).first)
}

val removeRelatePromoteSwitch = switchPrefsItem(string(R.string.filter_search_remove_relate_promote))
.let { root.addView(it.first); it.second }
removeRelatePromoteSwitch.isChecked = prefs.getBoolean("search_filter_remove_relate_promote", false)

setTitle(string(R.string.filter_search_title))

setPositiveButton(android.R.string.ok) { _, _ ->
Expand All @@ -61,6 +65,7 @@ class SearchFilterDialog(activity: Activity, prefs: SharedPreferences) :
putStringSet("search_filter_keyword_upname", upNameGroup.getKeywords())
putStringSet("search_filter_keyword_uid", uidGroup.getKeywords())
putBoolean("search_filter_content_regex_mode", contentRegexMode)
putBoolean("search_filter_remove_relate_promote", removeRelatePromoteSwitch.isChecked)
}.apply()
Log.toast(string(R.string.prefs_save_success_and_reboot))
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) {
val searchFilterUpNames = run {
sPrefs.getStringSet("search_filter_keyword_upname", null).orEmpty()
}
val searchRemoveRelatePromote = sPrefs.getBoolean("search_filter_remove_relate_promote", false)
val commentFilterAtUid = run {
sPrefs.getStringSet("comment_filter_keyword_at_uid", null)
?.mapNotNull { it.toLongOrNull() }.orEmpty()
Expand Down Expand Up @@ -465,13 +466,19 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
}
}
val needSearchFilter = hidden and (searchFilterContents.isNotEmpty() or searchFilterUid.isNotEmpty() or searchFilterUpNames.isNotEmpty())
val needSearchFilter = hidden and (searchFilterContents.isNotEmpty() or searchFilterUid.isNotEmpty() or searchFilterUpNames.isNotEmpty()) or searchRemoveRelatePromote
if (needSearchFilter) {
instance.searchAllResponseClass?.hookAfterMethod("getItemList") { p ->
val items = p.result as? List<Any?> ?: return@hookAfterMethod
p.result = items.filter { item ->
val videoCard = item?.getObjectField("cardItem_") ?: return@filter true
if (instance.searchVideoCardClass?.isInstance(videoCard) == false) return@filter true
if (instance.searchVideoCardClass?.isInstance(videoCard) == false) {
if (searchRemoveRelatePromote) {
if (item.callMethodAs<Boolean>("hasCm")) return@filter false
if (item.callMethodAs<Boolean>("hasSpecial")) return@filter false
}
return@filter true
}
if (videoCard.getLongField("mid_") in searchFilterUid) return@filter false
if (videoCard.getObjectFieldAs<String>("author_") in searchFilterUpNames) return@filter false
if (searchFilterContentRegexMode) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,5 @@
<string name="support_summary">捐贈以支持模組開發</string>
<string name="pegasus_cover_ratio_title">推薦封面比例</string>
<string name="pegasus_cover_ratio_summary">自訂首頁推薦小卡(雙列顯示的)封面比例</string>
<string name="filter_search_remove_relate_promote">搜尋結果移除推廣</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
<string name="filter_search_title">过滤搜索</string>
<string name="filter_search_summary">按内容过滤搜索结果</string>
<string name="filter_search_video">过滤视频</string>
<string name="filter_search_remove_relate_promote">搜索结果移除推广</string>
<string name="filter_comment_title">过滤评论</string>
<string name="filter_comment_summary">按内容过滤评论</string>
<string name="keyword_group_name_at_up">\@的用户名</string>
Expand Down

0 comments on commit 233a877

Please sign in to comment.