mirror of
https://github.com/revanced/revanced-patches
synced 2024-08-31 11:35:34 +02:00
feat(youtube/comments): hide shorts comments button (#866)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
76f6ed34c1
commit
c78a74e21b
@ -0,0 +1,23 @@
|
||||
package app.revanced.patches.youtube.layout.comments.bytecode.fingerprints
|
||||
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patches.youtube.layout.comments.annotations.CommentsCompatibility
|
||||
import app.revanced.patches.youtube.layout.comments.resource.patch.CommentsResourcePatch
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
@Name("shorts-comments-button-fingerprint")
|
||||
@CommentsCompatibility
|
||||
@Version("0.0.1")
|
||||
object ShortsCommentsButtonFingerprint : MethodFingerprint(
|
||||
"V", AccessFlags.PRIVATE or AccessFlags.FINAL, listOf("Z", "Z", "L"),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation?.instructions?.any {
|
||||
it.opcode.ordinal == Opcode.CONST.ordinal && (it as WideLiteralInstruction).wideLiteral == CommentsResourcePatch.shortsCommentsButtonId
|
||||
} == true
|
||||
}
|
||||
)
|
@ -0,0 +1,68 @@
|
||||
package app.revanced.patches.youtube.layout.comments.bytecode.patch
|
||||
|
||||
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.addInstructions
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
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.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
||||
import app.revanced.patches.youtube.layout.comments.annotations.CommentsCompatibility
|
||||
import app.revanced.patches.youtube.layout.comments.bytecode.fingerprints.ShortsCommentsButtonFingerprint
|
||||
import app.revanced.patches.youtube.layout.comments.resource.patch.CommentsResourcePatch
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.PreferenceScreen
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
|
||||
@Patch
|
||||
@DependsOn([IntegrationsPatch::class, CommentsResourcePatch::class])
|
||||
@Name("comments")
|
||||
@Description("Hides components related to comments.")
|
||||
@CommentsCompatibility
|
||||
@Version("0.0.1")
|
||||
class CommentsPatch : BytecodePatch(
|
||||
listOf(
|
||||
ShortsCommentsButtonFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
val shortsCommentsButtonResult = ShortsCommentsButtonFingerprint.result!!
|
||||
val shortsCommentsButtonMethod = shortsCommentsButtonResult.mutableMethod
|
||||
|
||||
val checkCastAnchorFingerprint = object : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.CONST,
|
||||
Opcode.CONST_HIGH16,
|
||||
Opcode.IF_EQZ,
|
||||
Opcode.CONST,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
)
|
||||
) {}
|
||||
|
||||
val checkCastAnchorIndex = checkCastAnchorFingerprint.also {
|
||||
it.resolve(context, shortsCommentsButtonMethod, shortsCommentsButtonResult.classDef)
|
||||
}.result!!.scanResult.patternScanResult!!.endIndex
|
||||
|
||||
shortsCommentsButtonMethod.addInstructions(
|
||||
checkCastAnchorIndex + 1, """
|
||||
invoke-static {v${(shortsCommentsButtonMethod.instruction(checkCastAnchorIndex) as OneRegisterInstruction).registerA}}, Lapp/revanced/integrations/patches/HideShortsCommentsButtonPatch;->hideShortsCommentsButton(Landroid/view/View;)V
|
||||
"""
|
||||
)
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package app.revanced.patches.youtube.layout.comments.patch
|
||||
package app.revanced.patches.youtube.layout.comments.resource.patch
|
||||
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
@ -8,8 +7,6 @@ import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
||||
import app.revanced.patches.youtube.layout.comments.annotations.CommentsCompatibility
|
||||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
@ -17,13 +14,15 @@ import app.revanced.patches.youtube.misc.settings.framework.components.impl.Pref
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference
|
||||
|
||||
@Patch
|
||||
@DependsOn([ResourceMappingResourcePatch::class, GeneralBytecodeAdsPatch::class])
|
||||
@Name("comments")
|
||||
@Description("Hides comments components below the video player.")
|
||||
@Name("comments-resource-patch")
|
||||
@CommentsCompatibility
|
||||
@DependsOn([SettingsPatch::class, ResourceMappingResourcePatch::class])
|
||||
@Version("0.0.1")
|
||||
class CommentsPatch : ResourcePatch {
|
||||
class CommentsResourcePatch : ResourcePatch {
|
||||
companion object {
|
||||
internal var shortsCommentsButtonId: Long = -1
|
||||
}
|
||||
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
||||
PreferenceScreen(
|
||||
@ -44,10 +43,22 @@ class CommentsPatch : ResourcePatch {
|
||||
StringResource("revanced_hide_preview_comment_on", "Preview comment is hidden"),
|
||||
StringResource("revanced_hide_preview_comment_off", "Preview comment is shown")
|
||||
),
|
||||
SwitchPreference(
|
||||
"revanced_hide_shorts_comments_button",
|
||||
StringResource("revanced_hide_shorts_comments_button_title", "Hide shorts comments button"),
|
||||
false,
|
||||
StringResource("revanced_hide_shorts_comments_button_on", "Shorts comments button is hidden"),
|
||||
StringResource("revanced_hide_shorts_comments_button_off", "Shorts comments button is shown")
|
||||
),
|
||||
),
|
||||
StringResource("revanced_comments_summary", "Manage the visibility of comments section components")
|
||||
)
|
||||
)
|
||||
|
||||
shortsCommentsButtonId = ResourceMappingResourcePatch.resourceMappings.single {
|
||||
it.type == "drawable" && it.name == "ic_right_comment_32c"
|
||||
}.id
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user