From 233a8778740ef4468fdaf1c6fb139e5bb91a3ee7 Mon Sep 17 00:00:00 2001 From: "Hydrogen.P" <77036672+CodePwn2021@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:16:08 +0800 Subject: [PATCH] feat: search filter add remove relate promote (#1567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 搜索过滤器新增移除推广(例如起飞推广) --- .../java/me/iacn/biliroaming/SearchFilterDialog.kt | 5 +++++ .../java/me/iacn/biliroaming/hook/ProtoBufHook.kt | 11 +++++++++-- app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/me/iacn/biliroaming/SearchFilterDialog.kt b/app/src/main/java/me/iacn/biliroaming/SearchFilterDialog.kt index bc2a8db93f..228358f5c8 100644 --- a/app/src/main/java/me/iacn/biliroaming/SearchFilterDialog.kt +++ b/app/src/main/java/me/iacn/biliroaming/SearchFilterDialog.kt @@ -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) { _, _ -> @@ -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)) } diff --git a/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt index f99fcea2bf..c934a56136 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt @@ -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() @@ -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 ?: 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("hasCm")) return@filter false + if (item.callMethodAs("hasSpecial")) return@filter false + } + return@filter true + } if (videoCard.getLongField("mid_") in searchFilterUid) return@filter false if (videoCard.getObjectFieldAs("author_") in searchFilterUpNames) return@filter false if (searchFilterContentRegexMode) { diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index fc0a55f207..8fc62f4829 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -277,4 +277,5 @@ 捐贈以支持模組開發 推薦封面比例 自訂首頁推薦小卡(雙列顯示的)封面比例 + 搜尋結果移除推廣 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b95913ccba..e98e706ee1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -282,6 +282,7 @@ 过滤搜索 按内容过滤搜索结果 过滤视频 + 搜索结果移除推广 过滤评论 按内容过滤评论 \@的用户名