mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-25 04:05:50 +01:00
feat(twitter/hide-recommended-users): hide "Who to follow"
This commit is contained in:
parent
cd93917148
commit
c7cabc0b57
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user