From 274247e6197dc2b40c365d1a9e7da79f8c1077e8 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 27 Mar 2023 22:31:10 +0900 Subject: [PATCH] add `hide-category-bar` patch --- .../FilterBarHeightFingerprint.kt | 21 +++++ .../RelatedChipCloudFingerprint.kt | 20 ++++ .../categorybar/patch/CategoryBarPatch.kt | 91 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 4 + .../youtube/settings/host/values/strings.xml | 6 +- .../youtube/settings/xml/revanced_prefs.xml | 5 + 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt new file mode 100644 index 000000000..90d67bc51 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt @@ -0,0 +1,21 @@ +package app.revanced.patches.youtube.layout.general.categorybar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +object FilterBarHeightFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IPUT + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.filterBarHeightLabelId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt new file mode 100644 index 000000000..7003a1ee0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.youtube.layout.general.categorybar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +object RelatedChipCloudFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.relatedChipCloudMarginLabelId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt new file mode 100644 index 000000000..920a0f976 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt @@ -0,0 +1,91 @@ +package app.revanced.patches.youtube.layout.general.categorybar.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.addInstruction +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +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.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.FilterBarHeightFingerprint +import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.RelatedChipCloudFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.GENERAL_LAYOUT +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@Name("hide-category-bar") +@Description("Hide the category bar at the top of the feed and at the top of related videos.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class CategoryBarPatch : BytecodePatch( + listOf( + FilterBarHeightFingerprint, + RelatedChipCloudFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + /** + * Category Bar in feed + * Home feed and subscriptions feed + */ + FilterBarHeightFingerprint.result?.let { + with (it.mutableMethod) { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInFeed(I)I + move-result v$register + """ + ) + } + } ?: return FilterBarHeightFingerprint.toErrorResult() + + /** + * Category Bar in related video + */ + RelatedChipCloudFingerprint.result?.let { + with (it.mutableMethod) { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + val register = (instruction(insertIndex) as OneRegisterInstruction).registerA + + addInstruction( + insertIndex + 1, + "invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInRelatedVideo(Landroid/view/View;)V" + ) + } + } ?: return RelatedChipCloudFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_LAYOUT_SETTINGS", + "SETTINGS: HIDE_CATEGORY_BAR" + ) + ) + + SettingsPatch.updatePatchStatus("hide-category-bar") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 348abe498..4ba6bd036 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -27,6 +27,7 @@ class SharedResourceIdPatch : ResourcePatch { var donationCompanionResourceId: Long = -1 var emptyColorLabelId: Long = -1 var fabLabelId: Long = -1 + var filterBarHeightLabelId: Long = -1 var floatyBarQueueLabelId: Long = -1 var imageOnlyTabId: Long = -1 var imageWithTextTabId: Long = -1 @@ -35,6 +36,7 @@ class SharedResourceIdPatch : ResourcePatch { var layoutVideo: Long = -1 var liveChatButtonId: Long = -1 var reelPlayerFooterLabelId: Long = -1 + var relatedChipCloudMarginLabelId: Long = -1 var scrubbingLabelId: Long = -1 var timeStampsContainerLabelId: Long = -1 var tooltipLabelId: Long = -1 @@ -58,6 +60,7 @@ class SharedResourceIdPatch : ResourcePatch { donationCompanionResourceId = findSharedResourceId("layout", "donation_companion") emptyColorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark") fabLabelId = findSharedResourceId("id", "fab") + filterBarHeightLabelId = findSharedResourceId("dimen", "filter_bar_height") floatyBarQueueLabelId = findSharedResourceId("string", "floaty_bar_queue_status") imageOnlyTabId = findSharedResourceId("layout", "image_only_tab") imageWithTextTabId = findSharedResourceId("layout", "image_with_text_tab") @@ -66,6 +69,7 @@ class SharedResourceIdPatch : ResourcePatch { layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video") liveChatButtonId = findSharedResourceId("id", "live_chat_overlay_button") reelPlayerFooterLabelId = findSharedResourceId("layout", "reel_player_dyn_footer_vert_stories3") + relatedChipCloudMarginLabelId = findSharedResourceId("layout", "related_chip_cloud_reduced_margins") scrubbingLabelId = findSharedResourceId("dimen", "vertical_touch_offset_to_enter_fine_scrubbing") timeStampsContainerLabelId = findSharedResourceId("id", "timestamps_container") tooltipLabelId = findSharedResourceId("layout", "tooltip_content_view") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 58ef3a191..8ce874701 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -298,6 +298,10 @@ Is it ready to submit?" Cast button is shown Cast button is hidden Hide cast button + Hide category bar in feed + Hide category bar in related video + Category bar is shown + Category bar is hidden Channel watermark is shown Channel watermark is hidden Hide channel watermark @@ -381,7 +385,7 @@ Is it ready to submit?" Hide stats for nerds menu Watch in VR menu is shown Watch in VR menu is hidden - Hide Watch in VR menu + Hide watch in VR menu Mix playlist is shown Mix playlist is hidden Hide mix playlist diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 5ac0bbb27..e016d41d9 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -116,6 +116,10 @@ + +