Skip to content

Commit

Permalink
feat(Twitter): Added Remove videos for you patch
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Aug 10, 2024
1 parent c0152e3 commit 25934a2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package crimera.patches.twitter.ads.timelineEntryHook

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

@Patch(
name = "Remove videos for you",
description = "Removes \"videos for you\" from explore",
dependencies = [SettingsPatch::class,TimelineModuleItemHookPatch::class],
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = true
)
object HideVideosForYou :BytecodePatch(
setOf(SettingsStatusLoadFingerprint)
){
override fun execute(context: BytecodeContext) {
SettingsStatusLoadFingerprint.enableSettings("hideVideosForYou")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package crimera.patches.twitter.ads.timelineEntryHook

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.misc.settings.SettingsPatch

object TimelineModuleItemHookFingerprint:MethodFingerprint(
returnType = "Ljava/lang/Object",
customFingerprint = {it,_->
it.definingClass == "Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem\$\$JsonObjectMapper;" && it.name == "parse"
}
)

@Patch(
compatiblePackages = [CompatiblePackage("com.twitter.android")],
)
object TimelineModuleItemHookPatch:BytecodePatch(
setOf(TimelineModuleItemHookFingerprint)
){
override fun execute(context: BytecodeContext) {
val TIMELINE_ENTRY_DESCRIPTOR = "${SettingsPatch.PATCHES_DESCRIPTOR}/TimelineEntry"

val result = TimelineModuleItemHookFingerprint.result
?:throw PatchException("TimelineModuleItemHookFingerprint not found")

val methods = result.mutableMethod
val instructions = methods.getInstructions()

val returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index

methods.addInstructions(returnObj,"""
invoke-static {p1}, $TIMELINE_ENTRY_DESCRIPTOR;->checkEntry(Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem;)Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem;
move-result-object p1
""".trimIndent())

//end
}
}
1 change: 1 addition & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="piko_pref_hide_g_ads">Google ads</string>
<string name="piko_pref_hide_main_event">Main event (Explore)</string>
<string name="piko_pref_hide_superhero_event">Superhero event (Explore)</string>
<string name="piko_pref_hide_videos_for_you">videos for you</string>
<string name="piko_pref_wtf_section">"Who to follow" section</string>
<string name="piko_pref_cts_section">"Creators to subscribe" section</string>
<string name="piko_pref_ctj_section">"Community to join" section</string>
Expand Down

0 comments on commit 25934a2

Please sign in to comment.