diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksDirectlyPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksDirectlyPatch.kt new file mode 100644 index 000000000..6c15d48ae --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksDirectlyPatch.kt @@ -0,0 +1,50 @@ +package app.revanced.patches.reddit.misc.openlink.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.misc.openlink.fingerprints.ScreenNavigatorFingerprint +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus + +@Patch +@Name("open-links-directly") +@Description("Skips over redirection URLs to external links.") +@DependsOn([SettingsPatch::class]) +@RedditCompatibility +@Version("0.0.1") +class OpenLinksDirectlyPatch : BytecodePatch( + listOf(ScreenNavigatorFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ScreenNavigatorFingerprint.result?.let { + it.mutableMethod.apply { + addInstructions( + 0, """ + invoke-static {p2}, $INTEGRATIONS_METHOD_DESCRIPTOR + move-result-object p2 + """ + ) + } + } ?: return ScreenNavigatorFingerprint.toErrorResult() + + updateSettingsStatus("OpenLinksDirectly") + + return PatchResultSuccess() + } + + private companion object { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/OpenLinksDirectlyPatch;" + + "->parseRedirectUri(Landroid/net/Uri;)Landroid/net/Uri;" + } +} \ No newline at end of file diff --git a/src/main/resources/reddit/settings/host/values/strings.xml b/src/main/resources/reddit/settings/host/values/strings.xml index 8cf12554b..628470d76 100644 --- a/src/main/resources/reddit/settings/host/values/strings.xml +++ b/src/main/resources/reddit/settings/host/values/strings.xml @@ -1,5 +1,7 @@ + Skips over redirection URLs to external links + Open links directly Open links outside of the app directly in your browser Open links externally Removes (tracking) query parameters from the URLs when sharing links