feat(X): Add Open links as query patch (#570)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
dic1911 2024-02-21 11:22:32 +08:00 committed by GitHub
parent 608c520a00
commit 95ca632d40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 17 deletions

View File

@ -9,8 +9,7 @@ import org.json.JSONObject
// https://raw.githubusercontent.com/Dr-TSNG/TwiFucker/880cdf1c1622e54ab45561ffcb4f53d94ed97bae/app/src/main/java/icu/nullptr/twifucker/hook/JsonHook.kt // https://raw.githubusercontent.com/Dr-TSNG/TwiFucker/880cdf1c1622e54ab45561ffcb4f53d94ed97bae/app/src/main/java/icu/nullptr/twifucker/hook/JsonHook.kt
internal object TwiFucker { internal object TwiFucker {
// root // root
private fun JSONObject.jsonGetInstructions(): JSONArray? = private fun JSONObject.jsonGetInstructions(): JSONArray? = optJSONObject("timeline")?.optJSONArray("instructions")
optJSONObject("timeline")?.optJSONArray("instructions")
private fun JSONObject.jsonGetData(): JSONObject? = optJSONObject("data") private fun JSONObject.jsonGetData(): JSONObject? = optJSONObject("data")
@ -42,10 +41,11 @@ internal object TwiFucker {
// data // data
private fun JSONObject.dataGetInstructions(): JSONArray? { private fun JSONObject.dataGetInstructions(): JSONArray? {
val timeline = optJSONObject("user_result")?.optJSONObject("result") val timeline =
?.optJSONObject("timeline_response")?.optJSONObject("timeline") optJSONObject("user_result")?.optJSONObject("result")
?: optJSONObject("timeline_response")?.optJSONObject("timeline") ?.optJSONObject("timeline_response")?.optJSONObject("timeline")
?: optJSONObject("timeline_response") ?: optJSONObject("timeline_response")?.optJSONObject("timeline")
?: optJSONObject("timeline_response")
return timeline?.optJSONArray("instructions") return timeline?.optJSONArray("instructions")
} }
@ -64,7 +64,6 @@ internal object TwiFucker {
} }
}?.optJSONObject("legacy") }?.optJSONObject("legacy")
// entry // entry
private fun JSONObject.entryHasPromotedMetadata(): Boolean = private fun JSONObject.entryHasPromotedMetadata(): Boolean =
optJSONObject("content")?.optJSONObject("item")?.optJSONObject("content") optJSONObject("content")?.optJSONObject("item")?.optJSONObject("content")
@ -77,11 +76,9 @@ internal object TwiFucker {
optJSONObject("content")?.optJSONArray("items") optJSONObject("content")?.optJSONArray("items")
?: optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") ?: optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items")
private fun JSONObject.entryIsTweetDetailRelatedTweets(): Boolean = private fun JSONObject.entryIsTweetDetailRelatedTweets(): Boolean = optString("entryId").startsWith("tweetdetailrelatedtweets-")
optString("entryId").startsWith("tweetdetailrelatedtweets-")
private fun JSONObject.entryGetTrends(): JSONArray? = private fun JSONObject.entryGetTrends(): JSONArray? = optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items")
optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items")
// trend // trend
private fun JSONObject.trendHasPromotedMetadata(): Boolean = private fun JSONObject.trendHasPromotedMetadata(): Boolean =
@ -104,8 +101,7 @@ internal object TwiFucker {
// instruction // instruction
private fun JSONObject.instructionTimelineAddEntries(): JSONArray? = optJSONArray("entries") private fun JSONObject.instructionTimelineAddEntries(): JSONArray? = optJSONArray("entries")
private fun JSONObject.instructionGetAddEntries(): JSONArray? = private fun JSONObject.instructionGetAddEntries(): JSONArray? = optJSONObject("addEntries")?.optJSONArray("entries")
optJSONObject("addEntries")?.optJSONArray("entries")
private fun JSONObject.instructionCheckAndRemove(action: (JSONArray) -> Unit) { private fun JSONObject.instructionCheckAndRemove(action: (JSONArray) -> Unit) {
instructionTimelineAddEntries()?.let(action) instructionTimelineAddEntries()?.let(action)
@ -164,9 +160,10 @@ internal object TwiFucker {
entriesRemoveTweetDetailRelatedTweets() entriesRemoveTweetDetailRelatedTweets()
} }
private fun JSONObject.entryIsWhoToFollow(): Boolean = optString("entryId").let { private fun JSONObject.entryIsWhoToFollow(): Boolean =
it.startsWith("whoToFollow-") || it.startsWith("who-to-follow-") || it.startsWith("connect-module-") optString("entryId").let {
} it.startsWith("whoToFollow-") || it.startsWith("who-to-follow-") || it.startsWith("connect-module-")
}
private fun JSONObject.itemContainsPromotedUser(): Boolean = private fun JSONObject.itemContainsPromotedUser(): Boolean =
optJSONObject("item")?.optJSONObject("content") optJSONObject("item")?.optJSONObject("content")
@ -217,4 +214,4 @@ internal object TwiFucker {
instruction.instructionCheckAndRemove(action) instruction.instructionCheckAndRemove(action)
} }
} }
} }

View File

@ -0,0 +1,12 @@
package app.revanced.integrations.twitter.patches.links;
import android.content.Context;
import android.content.Intent;
public final class OpenLinksWithAppChooserPatch {
public static void openWithChooser(final Context context, final Intent intent) {
intent.setAction("android.intent.action.VIEW");
context.startActivity(Intent.createChooser(intent, null));
}
}