feat(twitter/hide-recommended-users): hide "Who to follow"

This commit is contained in:
oSumAtrIX 2023-05-20 04:33:10 +02:00
parent cd93917148
commit c7cabc0b57
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -51,7 +51,7 @@ internal object TwiFucker {
private fun JSONObject.dataCheckAndRemove() { private fun JSONObject.dataCheckAndRemove() {
dataGetInstructions()?.forEach { instruction -> dataGetInstructions()?.forEach { instruction ->
instruction.instructionCheckAndRemove() instruction.instructionCheckAndRemove { it.entriesRemoveAnnoyance() }
} }
} }
@ -107,9 +107,9 @@ internal object TwiFucker {
private fun JSONObject.instructionGetAddEntries(): JSONArray? = private fun JSONObject.instructionGetAddEntries(): JSONArray? =
optJSONObject("addEntries")?.optJSONArray("entries") optJSONObject("addEntries")?.optJSONArray("entries")
private fun JSONObject.instructionCheckAndRemove() { private fun JSONObject.instructionCheckAndRemove(action: (JSONArray) -> Unit) {
instructionTimelineAddEntries()?.entriesRemoveAnnoyance() instructionTimelineAddEntries()?.let(action)
instructionGetAddEntries()?.entriesRemoveAnnoyance() instructionGetAddEntries()?.let(action)
} }
// entries // entries
@ -164,14 +164,57 @@ internal object TwiFucker {
entriesRemoveTweetDetailRelatedTweets() entriesRemoveTweetDetailRelatedTweets()
} }
private fun JSONObject.entryIsWhoToFollow(): Boolean = optString("entryId").let {
it.startsWith("whoToFollow-") || it.startsWith("who-to-follow-") || it.startsWith("connect-module-")
}
private fun JSONObject.itemContainsPromotedUser(): Boolean =
optJSONObject("item")?.optJSONObject("content")
?.has("userPromotedMetadata") == true || optJSONObject("item")?.optJSONObject("content")
?.optJSONObject("user")
?.has("userPromotedMetadata") == true || optJSONObject("item")?.optJSONObject("content")
?.optJSONObject("user")?.has("promotedMetadata") == true
fun JSONArray.entriesRemoveWhoToFollow() {
val entryRemoveIndex = mutableListOf<Int>()
forEachIndexed { entryIndex, entry ->
if (!entry.entryIsWhoToFollow()) return@forEachIndexed
Log.d("revanced", "Handle whoToFollow $entryIndex $entry")
entryRemoveIndex.add(entryIndex)
val items = entry.entryGetContentItems()
val userRemoveIndex = mutableListOf<Int>()
items?.forEachIndexed { index, item ->
item.itemContainsPromotedUser().let {
if (it) {
Log.d("revanced", "Handle whoToFollow promoted user $index $item")
userRemoveIndex.add(index)
}
}
}
for (i in userRemoveIndex.reversed()) {
items?.remove(i)
}
}
for (i in entryRemoveIndex.reversed()) {
remove(i)
}
}
fun hideRecommendedUsers(json: JSONObject) { fun hideRecommendedUsers(json: JSONObject) {
json.filterInstructions { it.entriesRemoveWhoToFollow() }
json.jsonCheckAndRemoveRecommendedUsers() json.jsonCheckAndRemoveRecommendedUsers()
} }
fun hidePromotedAds(json: JSONObject) { fun hidePromotedAds(json: JSONObject) {
json.jsonGetInstructions()?.forEach { instruction -> json.filterInstructions { it.entriesRemoveAnnoyance() }
instruction.instructionCheckAndRemove()
}
json.jsonGetData()?.dataCheckAndRemove() json.jsonGetData()?.dataCheckAndRemove()
} }
private fun JSONObject.filterInstructions(action: (JSONArray) -> Unit) {
jsonGetInstructions()?.forEach { instruction ->
instruction.instructionCheckAndRemove(action)
}
}
} }