feat(reddit): add open-links-directly patch

This commit is contained in:
inotia00 2023-06-23 19:02:51 +09:00
parent 0306d18c43
commit 5080ae5452
2 changed files with 52 additions and 0 deletions

View File

@ -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;"
}
}

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="revanced_enable_open_links_directly_summary">Skips over redirection URLs to external links</string>
<string name="revanced_enable_open_links_directly_title">Open links directly</string>
<string name="revanced_enable_open_links_externally_summary">Open links outside of the app directly in your browser</string>
<string name="revanced_enable_open_links_externally_title">Open links externally</string>
<string name="revanced_enable_sanitize_url_query_summary">Removes (tracking) query parameters from the URLs when sharing links</string>