From ee3bcf17900dfe549a07426182a2149bcf16f87a Mon Sep 17 00:00:00 2001 From: crimera Date: Thu, 8 Feb 2024 18:43:17 +0800 Subject: [PATCH] feat(twitter): Add selectable text patch --- .../selectabletext/SelectableTextPatch.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/kotlin/crimera/patches/twitter/selectabletext/SelectableTextPatch.kt diff --git a/src/main/kotlin/crimera/patches/twitter/selectabletext/SelectableTextPatch.kt b/src/main/kotlin/crimera/patches/twitter/selectabletext/SelectableTextPatch.kt new file mode 100644 index 00000000..76a4bf03 --- /dev/null +++ b/src/main/kotlin/crimera/patches/twitter/selectabletext/SelectableTextPatch.kt @@ -0,0 +1,36 @@ +package crimera.patches.twitter.selectabletext + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotation.Patch +import org.w3c.dom.Element + +@Patch( + name = "SelectableTextPatch", + description = "Makes bio and username selectable", +) +@Suppress("unused") +object SelectableTextPatch: ResourcePatch() { + override fun execute(context: ResourceContext) { + val profileDetailsXml = context["res/layout/profile_details.xml"] + if (!profileDetailsXml.exists()) throw PatchException("profile_details.xml not found") + + val ids = listOf( + "user_name", + "user_bio", + ).map { "@id/$it" } + + context.xmlEditor["res/layout/profile_details.xml"].use { editor -> + val texts = editor.file.getElementsByTagName("com.twitter.ui.components.text.legacy.TypefacesTextView") + for (i in 0 until texts.length) { + val text = texts.item(i) as Element + val id = text.getAttribute("android:id") + + if (ids.contains(id)) { + text.setAttribute("android:textIsSelectable", "true") + } + } + } + } +} \ No newline at end of file