From 95ca632d40b90ea8160dbbf33fd5d7f2281cf711 Mon Sep 17 00:00:00 2001 From: dic1911 Date: Wed, 21 Feb 2024 11:22:32 +0800 Subject: [PATCH] feat(X): Add `Open links as query` patch (#570) Co-authored-by: oSumAtrIX --- .../patches/hook/twifucker/TwiFucker.kt | 31 +++++++++---------- .../links/OpenLinksWithAppChooserPatch.java | 12 +++++++ 2 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/app/revanced/integrations/twitter/patches/links/OpenLinksWithAppChooserPatch.java diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt index 247ef0a3..282c0c60 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt @@ -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 internal object TwiFucker { // root - private fun JSONObject.jsonGetInstructions(): JSONArray? = - optJSONObject("timeline")?.optJSONArray("instructions") + private fun JSONObject.jsonGetInstructions(): JSONArray? = optJSONObject("timeline")?.optJSONArray("instructions") private fun JSONObject.jsonGetData(): JSONObject? = optJSONObject("data") @@ -42,10 +41,11 @@ internal object TwiFucker { // data private fun JSONObject.dataGetInstructions(): JSONArray? { - val timeline = optJSONObject("user_result")?.optJSONObject("result") - ?.optJSONObject("timeline_response")?.optJSONObject("timeline") - ?: optJSONObject("timeline_response")?.optJSONObject("timeline") - ?: optJSONObject("timeline_response") + val timeline = + optJSONObject("user_result")?.optJSONObject("result") + ?.optJSONObject("timeline_response")?.optJSONObject("timeline") + ?: optJSONObject("timeline_response")?.optJSONObject("timeline") + ?: optJSONObject("timeline_response") return timeline?.optJSONArray("instructions") } @@ -64,7 +64,6 @@ internal object TwiFucker { } }?.optJSONObject("legacy") - // entry private fun JSONObject.entryHasPromotedMetadata(): Boolean = optJSONObject("content")?.optJSONObject("item")?.optJSONObject("content") @@ -77,11 +76,9 @@ internal object TwiFucker { optJSONObject("content")?.optJSONArray("items") ?: optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") - private fun JSONObject.entryIsTweetDetailRelatedTweets(): Boolean = - optString("entryId").startsWith("tweetdetailrelatedtweets-") + private fun JSONObject.entryIsTweetDetailRelatedTweets(): Boolean = optString("entryId").startsWith("tweetdetailrelatedtweets-") - private fun JSONObject.entryGetTrends(): JSONArray? = - optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") + private fun JSONObject.entryGetTrends(): JSONArray? = optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") // trend private fun JSONObject.trendHasPromotedMetadata(): Boolean = @@ -104,8 +101,7 @@ internal object TwiFucker { // instruction private fun JSONObject.instructionTimelineAddEntries(): JSONArray? = optJSONArray("entries") - private fun JSONObject.instructionGetAddEntries(): JSONArray? = - optJSONObject("addEntries")?.optJSONArray("entries") + private fun JSONObject.instructionGetAddEntries(): JSONArray? = optJSONObject("addEntries")?.optJSONArray("entries") private fun JSONObject.instructionCheckAndRemove(action: (JSONArray) -> Unit) { instructionTimelineAddEntries()?.let(action) @@ -164,9 +160,10 @@ internal object TwiFucker { entriesRemoveTweetDetailRelatedTweets() } - private fun JSONObject.entryIsWhoToFollow(): Boolean = optString("entryId").let { - it.startsWith("whoToFollow-") || it.startsWith("who-to-follow-") || it.startsWith("connect-module-") - } + 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") @@ -217,4 +214,4 @@ internal object TwiFucker { instruction.instructionCheckAndRemove(action) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/links/OpenLinksWithAppChooserPatch.java b/app/src/main/java/app/revanced/integrations/twitter/patches/links/OpenLinksWithAppChooserPatch.java new file mode 100644 index 00000000..e781f19a --- /dev/null +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/links/OpenLinksWithAppChooserPatch.java @@ -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)); + } +}