From 0d3d9bbe9feb16e8956985dda1ae94a5544478ec Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 29 Jun 2023 17:46:24 +0900 Subject: [PATCH] feat(youtube): add `hide-trending-searches` patch --- .../fingerprints/SearchBarEntryFingerprint.kt | 19 +++++ .../patch/TrendingSearchesPatch.kt | 82 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 6 ++ .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 + 5 files changed, 114 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/fingerprints/SearchBarEntryFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/patch/TrendingSearchesPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/fingerprints/SearchBarEntryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/fingerprints/SearchBarEntryFingerprint.kt new file mode 100644 index 000000000..9655317f9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/fingerprints/SearchBarEntryFingerprint.kt @@ -0,0 +1,19 @@ +package app.revanced.patches.youtube.general.trendingsearches.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineArrowTimeBlack +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineFireBlack +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineSearchBlack +import app.revanced.util.bytecode.isWideLiteralExists +import org.jf.dexlib2.AccessFlags + +object SearchBarEntryFingerprint : MethodFingerprint( + returnType = "L", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + customFingerprint = { methodDef, _ -> + methodDef.isWideLiteralExists(YtOutlineArrowTimeBlack) + && methodDef.isWideLiteralExists(YtOutlineFireBlack) + && methodDef.isWideLiteralExists(YtOutlineSearchBlack) + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/patch/TrendingSearchesPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/patch/TrendingSearchesPatch.kt new file mode 100644 index 000000000..b6605e059 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/trendingsearches/patch/TrendingSearchesPatch.kt @@ -0,0 +1,82 @@ +package app.revanced.patches.youtube.general.trendingsearches.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.youtube.general.trendingsearches.fingerprints.SearchBarEntryFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.GENERAL +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineArrowTimeBlack +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineFireBlack +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.YtOutlineSearchBlack +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@Name("hide-trending-searches") +@Description("Hide trending searches in the search bar.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class TrendingSearchesPatch : BytecodePatch( + listOf(SearchBarEntryFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + SearchBarEntryFingerprint.result?.let { + it.mutableMethod.apply { + SearchTerm.values() + .map { searchTerm -> getWideLiteralIndex(searchTerm.resourceId) to searchTerm.value } + .sortedBy { searchTerm -> searchTerm.first } + .reversed() + .forEach { (index, value) -> + val freeRegister = getInstruction(index).registerA + val viewRegister = getInstruction(index - 1).registerA + + addInstructions( + index, """ + const/4 v$freeRegister, $value + invoke-static {v$viewRegister, v$freeRegister}, $GENERAL->hideTrendingSearches(Landroid/widget/ImageView;Z)V + """ + ) + } + } + } ?: return SearchBarEntryFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_SETTINGS", + "SETTINGS: HIDE_TRENDING_SEARCHES" + ) + ) + + SettingsPatch.updatePatchStatus("hide-trending-searches") + + return PatchResultSuccess() + } + private enum class SearchTerm(val resourceId: Long, val value: Int) { + HISTORY(YtOutlineArrowTimeBlack, 0), + SEARCH(YtOutlineSearchBlack, 0), + TRENDING(YtOutlineFireBlack, 1) + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt index fdca3024b..9ee901da0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -81,6 +81,9 @@ class SharedResourceIdPatch : ResourcePatch { var VideoZoomIndicatorLayout: Long = -1 var WordMarkHeader: Long = -1 var YoutubeControlsOverlay: Long = -1 + var YtOutlineArrowTimeBlack: Long = -1 + var YtOutlineFireBlack: Long = -1 + var YtOutlineSearchBlack: Long = -1 } override fun execute(context: ResourceContext): PatchResult { @@ -148,6 +151,9 @@ class SharedResourceIdPatch : ResourcePatch { VideoZoomIndicatorLayout = find(ID, "video_zoom_indicator_layout") WordMarkHeader = find(ATTR, "ytWordmarkHeader") YoutubeControlsOverlay = find(ID, "youtube_controls_overlay") + YtOutlineArrowTimeBlack = find(DRAWABLE, "yt_outline_arrow_time_black_24") + YtOutlineFireBlack = find(DRAWABLE, "yt_outline_fire_black_24") + YtOutlineSearchBlack = find(DRAWABLE, "yt_outline_search_black_24") return PatchResultSuccess() } diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index d52f64b14..73cc99821 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -472,6 +472,9 @@ Only available on YouTube v18.24.37+" Time stamp is shown Time stamp is hidden Hide time stamp + Trending searches are shown + Trending searches are hidden + Hide trending searches Video ads are shown Video ads are hidden Hide video ads diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index e4e7e1255..925e30a8a 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -175,6 +175,9 @@ + + @@ -310,6 +313,7 @@ +