forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
hide-load-more-button
patch (ReVanced#2078)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
1 parent
470edfa
commit 7170802
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...patches/youtube/layout/hide/loadmorebutton/annotations/HideLoadMoreButtonCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package app.revanced.patches.youtube.layout.hide.loadmorebutton.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf( | ||
"17.49.37", | ||
"18.03.36", | ||
"18.03.42", | ||
"18.04.35", | ||
"18.04.41", | ||
"18.05.32", | ||
"18.05.35", | ||
"18.05.40", | ||
"18.08.37", | ||
"18.15.40", | ||
"18.16.37" | ||
) | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class HideLoadMoreButtonCompatibility | ||
|
29 changes: 29 additions & 0 deletions
29
...youtube/layout/hide/loadmorebutton/bytecode/fingerprints/HideLoadMoreButtonFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package app.revanced.patches.youtube.layout.hide.loadmorebutton.bytecode.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.hide.loadmorebutton.resource.patch.HideLoadMoreButtonResourcePatch | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
object HideLoadMoreButtonFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, | ||
parameters = listOf("L", "L", "L", "L"), | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT | ||
), | ||
customFingerprint = { methodDef -> | ||
methodDef.implementation?.instructions?.any { | ||
if (it.opcode != Opcode.CONST) return@any false | ||
|
||
val literal = (it as WideLiteralInstruction).wideLiteral | ||
|
||
literal == HideLoadMoreButtonResourcePatch.expandButtonDownId | ||
} ?: false | ||
} | ||
) |
47 changes: 47 additions & 0 deletions
47
...nced/patches/youtube/layout/hide/loadmorebutton/bytecode/patch/HideLoadMoreButtonPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package app.revanced.patches.youtube.layout.hide.loadmorebutton.bytecode.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.addInstruction | ||
import app.revanced.patcher.extensions.instruction | ||
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.youtube.layout.hide.loadmorebutton.bytecode.fingerprints.HideLoadMoreButtonFingerprint | ||
import app.revanced.patches.youtube.layout.hide.loadmorebutton.resource.patch.HideLoadMoreButtonResourcePatch | ||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch | ||
@Name("hide-load-more-button") | ||
@Description("Hides the button under videos that loads similar videos.") | ||
@DependsOn([HideLoadMoreButtonResourcePatch::class]) | ||
@Version("0.0.1") | ||
class HideLoadMoreButtonPatch : BytecodePatch(listOf(HideLoadMoreButtonFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
HideLoadMoreButtonFingerprint.result?.let { | ||
it.mutableMethod.apply { | ||
val moveRegisterIndex = it.scanResult.patternScanResult!!.endIndex | ||
val viewRegister = instruction<TwoRegisterInstruction>(moveRegisterIndex).registerA | ||
|
||
val insertIndex = moveRegisterIndex + 1 | ||
addInstruction( | ||
insertIndex, | ||
"invoke-static { v$viewRegister }, " + | ||
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideLoadMoreButton(Landroid/view/View;)V" | ||
) | ||
} | ||
} ?: return HideLoadMoreButtonFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/integrations/patches/HideLoadMoreButtonPatch;" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ches/youtube/layout/hide/loadmorebutton/resource/patch/HideLoadMoreButtonResourcePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package app.revanced.patches.youtube.layout.hide.loadmorebutton.resource.patch | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.layout.hide.loadmorebutton.annotations.HideLoadMoreButtonCompatibility | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
|
||
@Name("hide-load-more-button-resource-patch") | ||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) | ||
@HideLoadMoreButtonCompatibility | ||
class HideLoadMoreButtonResourcePatch : ResourcePatch { | ||
override fun execute(context: ResourceContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_hide_load_more_button", | ||
StringResource("revanced_hide_load_more_button_title", "Hide Load More button"), | ||
true, | ||
StringResource("revanced_hide_load_more_button_summary_on", "Load More button is hidden"), | ||
StringResource("revanced_hide_load_more_button_summary_off", "Load More button is shown") | ||
) | ||
) | ||
|
||
expandButtonDownId = ResourceMappingPatch.resourceMappings.single { | ||
it.type == "layout" && it.name == "expand_button_down" | ||
}.id | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
internal companion object { | ||
var expandButtonDownId: Long = -1 | ||
} | ||
} |