generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(twitter): Add selectable text patch
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/crimera/patches/twitter/selectabletext/SelectableTextPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} | ||
} | ||
} | ||
} |