From d32d1d340d9e3998b2543d83046c22706dc80d15 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 27 Jun 2023 01:50:59 +0900 Subject: [PATCH] feat(youtube/hide-shorts-component): hide likes, dislikes and share buttons in shorts player --- .../fingerprints/ShortsDislikeFingerprint.kt | 11 ++++ .../fingerprints/ShortsLikeFingerprint.kt | 11 ++++ .../fingerprints/ShortsShareFingerprint.kt | 11 ++++ .../patch/ShortsComponentPatch.kt | 3 ++ .../patch/ShortsDislikeButtonPatch.kt | 51 ++++++++++++++++++ .../patch/ShortsLikeButtonPatch.kt | 52 +++++++++++++++++++ .../patch/ShortsShareButtonPatch.kt | 41 +++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 6 +++ .../youtube/settings/values-v21/strings.xml | 15 ++++-- .../youtube/settings/xml/revanced_prefs.xml | 6 +-- 10 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsDislikeFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsLikeFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsShareFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsDislikeButtonPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsLikeButtonPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsShareButtonPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsDislikeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsDislikeFingerprint.kt new file mode 100644 index 000000000..c0ffe3b7d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsDislikeFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelRightDislikeIcon +import app.revanced.util.bytecode.isWideLiteralExists + +object ShortsDislikeFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Z", "Z", "L"), + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(ReelRightDislikeIcon) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsLikeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsLikeFingerprint.kt new file mode 100644 index 000000000..6c938cd5d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsLikeFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelRightLikeIcon +import app.revanced.util.bytecode.isWideLiteralExists + +object ShortsLikeFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Z", "Z", "L"), + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(ReelRightLikeIcon) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsShareFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsShareFingerprint.kt new file mode 100644 index 000000000..f250db521 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ShortsShareFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelDynShare +import app.revanced.util.bytecode.isWideLiteralExists + +object ShortsShareFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Z", "Z", "L"), + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(ReelDynShare) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt index ced0de565..481a490fa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt @@ -26,10 +26,13 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH SettingsPatch::class, SharedResourceIdPatch::class, ShortsCommentButtonPatch::class, + ShortsDislikeButtonPatch::class, ShortsInfoPanelPatch::class, + ShortsLikeButtonPatch::class, ShortsNavigationBarPatch::class, ShortsPaidContentBannerPatch::class, ShortsRemixButtonPatch::class, + ShortsShareButtonPatch::class, ShortsSubscriptionsButtonPatch::class ] ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsDislikeButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsDislikeButtonPatch.kt new file mode 100644 index 000000000..0fcfbd527 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsDislikeButtonPatch.kt @@ -0,0 +1,51 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +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.util.smali.ExternalLabel +import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsDislikeFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelRightDislikeIcon +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.SHORTS +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Name("hide-shorts-dislike") +@YouTubeCompatibility +@Version("0.0.1") +class ShortsDislikeButtonPatch : BytecodePatch( + listOf(ShortsDislikeFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ShortsDislikeFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = getWideLiteralIndex(ReelRightDislikeIcon) + val insertRegister = getInstruction(insertIndex).registerA + + for (index in insertIndex until implementation!!.instructions.size) { + if (getInstruction(index).opcode != Opcode.CONST_CLASS) continue + + addInstructionsWithLabels( + insertIndex + 1, """ + invoke-static {}, $SHORTS->hideShortsPlayerDislikeButton()Z + move-result v$insertRegister + if-nez v$insertRegister, :hide + const v$insertRegister, $ReelRightDislikeIcon + """, ExternalLabel("hide", getInstruction(index + 2)) + ) + break + } + } + } ?: return ShortsDislikeFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsLikeButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsLikeButtonPatch.kt new file mode 100644 index 000000000..f446d2eb6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsLikeButtonPatch.kt @@ -0,0 +1,52 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsLikeFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelRightLikeIcon +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.SHORTS +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Name("hide-shorts-like") +@YouTubeCompatibility +@Version("0.0.1") +class ShortsLikeButtonPatch : BytecodePatch( + listOf(ShortsLikeFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ShortsLikeFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = getWideLiteralIndex(ReelRightLikeIcon) + val insertRegister = getInstruction(insertIndex).registerA + + for (index in insertIndex until implementation!!.instructions.size) { + if (getInstruction(index).opcode != Opcode.CONST_CLASS) continue + + addInstructionsWithLabels( + insertIndex + 1, """ + invoke-static {}, $SHORTS->hideShortsPlayerLikeButton()Z + move-result v$insertRegister + if-nez v$insertRegister, :hide + const v$insertRegister, $ReelRightLikeIcon + """, ExternalLabel("hide", getInstruction(index + 2)) + ) + break + } + } + } ?: return ShortsLikeFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsShareButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsShareButtonPatch.kt new file mode 100644 index 000000000..d2808699c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsShareButtonPatch.kt @@ -0,0 +1,41 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +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.patches.youtube.shorts.shortscomponent.fingerprints.ShortsShareFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelDynShare +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.SHORTS +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Name("hide-shorts-share") +@YouTubeCompatibility +@Version("0.0.1") +class ShortsShareButtonPatch : BytecodePatch( + listOf(ShortsShareFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ShortsShareFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = getWideLiteralIndex(ReelDynShare) - 2 + val insertRegister = getInstruction(insertIndex).registerA + + addInstruction( + insertIndex, + "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerShareButton(Landroid/view/View;)V" + ) + + } + } ?: return ShortsShareFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} 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 9991196e6..1f8738d78 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 @@ -60,11 +60,14 @@ class SharedResourceIdPatch : ResourcePatch { var MusicAppDeeplinkButtonView: Long = -1 var QuickActionsElementContainer: Long = -1 var ReelDynRemix: Long = -1 + var ReelDynShare: Long = -1 var ReelPlayerBadge: Long = -1 var ReelPlayerBadge2: Long = -1 var ReelPlayerFooter: Long = -1 var ReelPlayerInfoPanel: Long = -1 var ReelPlayerPausedStateButton: Long = -1 + var ReelRightDislikeIcon: Long = -1 + var ReelRightLikeIcon: Long = -1 var RelatedChipCloudMargin: Long = -1 var RightComment: Long = -1 var ScrimOverlay: Long = -1 @@ -125,11 +128,14 @@ class SharedResourceIdPatch : ResourcePatch { MusicAppDeeplinkButtonView = find(ID, "music_app_deeplink_button_view") QuickActionsElementContainer = find(ID, "quick_actions_element_container") ReelDynRemix = find(ID, "reel_dyn_remix") + ReelDynShare = find(ID, "reel_dyn_share") ReelPlayerBadge = find(ID, "reel_player_badge") ReelPlayerBadge2 = find(ID, "reel_player_badge2") ReelPlayerFooter = find(LAYOUT, "reel_player_dyn_footer_vert_stories3") ReelPlayerInfoPanel = find(ID, "reel_player_info_panel") ReelPlayerPausedStateButton = find(ID, "reel_player_paused_state_buttons") + ReelRightDislikeIcon = find(DRAWABLE, "reel_right_dislike_icon") + ReelRightLikeIcon = find(DRAWABLE, "reel_right_like_icon") RelatedChipCloudMargin = find(LAYOUT, "related_chip_cloud_reduced_margins") RightComment = find(DRAWABLE, "ic_right_comment_32c") ScrimOverlay = find(ID, "scrim_overlay") diff --git a/src/main/resources/youtube/settings/values-v21/strings.xml b/src/main/resources/youtube/settings/values-v21/strings.xml index 310170b27..52a87bb66 100644 --- a/src/main/resources/youtube/settings/values-v21/strings.xml +++ b/src/main/resources/youtube/settings/values-v21/strings.xml @@ -36,18 +36,27 @@ @string/revanced_hide_button_share_title + @string/revanced_hide_button_dislike_summary_off + @string/revanced_hide_button_dislike_summary_on + @string/revanced_hide_button_dislike_title @string/revanced_hide_info_panel_summary_off @string/revanced_hide_info_panel_summary_on @string/revanced_hide_info_panel_title @string/revanced_hide_join_button_summary_off @string/revanced_hide_join_button_summary_on @string/revanced_hide_join_button_title - @string/revanced_ad_remover_paid_content_summary_off - @string/revanced_ad_remover_paid_content_summary_on - @string/revanced_ad_remover_paid_content_title + @string/revanced_hide_button_like_summary_off + @string/revanced_hide_button_like_summary_on + @string/revanced_hide_button_like_title + @string/revanced_hide_paid_content_summary_off + @string/revanced_hide_paid_content_summary_on + @string/revanced_hide_paid_content_title @string/revanced_hide_button_remix_summary_off @string/revanced_hide_button_remix_summary_on @string/revanced_hide_button_remix_title + @string/revanced_hide_button_share_summary_off + @string/revanced_hide_button_share_summary_on + @string/revanced_hide_button_share_title @string/revanced_hide_button_thanks_summary_off @string/revanced_hide_button_thanks_summary_on @string/revanced_hide_button_thanks_title diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 0c1aea7ef..a179f25de 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -479,9 +479,6 @@ - - @@ -545,10 +542,13 @@