Skip to content

Commit b007e8e

Browse files
fix(YouTube - Hide load more button): Include patch with Hide layout components, and hide button only in search feed (#2959)
1 parent 9479a95 commit b007e8e

File tree

9 files changed

+57
-101
lines changed

9 files changed

+57
-101
lines changed

src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.revanced.patches.youtube.layout.hide.general
22

33
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
45
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
56
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
67
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
@@ -17,16 +18,17 @@ import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
1718
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sorting
1819
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1920
import app.revanced.patches.shared.misc.settings.preference.TextPreference
21+
import app.revanced.patches.youtube.layout.hide.general.fingerprints.HideShowMoreButtonFingerprint
2022
import app.revanced.patches.youtube.layout.hide.general.fingerprints.ParseElementFromBufferFingerprint
2123
import app.revanced.patches.youtube.layout.hide.general.fingerprints.PlayerOverlayFingerprint
2224
import app.revanced.patches.youtube.layout.hide.general.fingerprints.ShowWatermarkFingerprint
2325
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
2426
import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch
25-
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
2627
import app.revanced.patches.youtube.misc.settings.SettingsPatch
2728
import app.revanced.util.resultOrThrow
2829
import com.android.tools.smali.dexlib2.Opcode
2930
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
31+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
3032
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
3133

3234
@Patch(
@@ -36,8 +38,8 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
3638
LithoFilterPatch::class,
3739
SettingsPatch::class,
3840
AddResourcesPatch::class,
39-
NavigationBarHookPatch::class,
40-
PlayerTypeHookPatch::class // Used by Keyword Content filter.
41+
HideLayoutComponentsResourcePatch::class,
42+
NavigationBarHookPatch::class // Used by Keyword Content filter.
4143
],
4244
compatiblePackages = [
4345
CompatiblePackage(
@@ -66,7 +68,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
6668
)
6769
@Suppress("unused")
6870
object HideLayoutComponentsPatch : BytecodePatch(
69-
setOf(ParseElementFromBufferFingerprint, PlayerOverlayFingerprint),
71+
setOf(ParseElementFromBufferFingerprint, PlayerOverlayFingerprint, HideShowMoreButtonFingerprint),
7072
) {
7173
private const val LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR =
7274
"Lapp/revanced/integrations/youtube/patches/components/LayoutComponentsFilter;"
@@ -122,9 +124,7 @@ object HideLayoutComponentsPatch : BytecodePatch(
122124
SwitchPreference("revanced_hide_notify_me_button"),
123125
SwitchPreference("revanced_hide_search_result_recommendations"),
124126
SwitchPreference("revanced_hide_search_result_shelf_header"),
125-
)
126-
127-
SettingsPatch.PreferenceScreen.FEED.addPreferences(
127+
SwitchPreference("revanced_hide_show_more_button"),
128128
PreferenceScreen(
129129
key = "revanced_hide_keyword_content_screen",
130130
sorting = Sorting.UNSORTED,
@@ -203,5 +203,24 @@ object HideLayoutComponentsPatch : BytecodePatch(
203203
}
204204

205205
// endregion
206+
207+
// region Show more button
208+
209+
HideShowMoreButtonFingerprint.resultOrThrow().let {
210+
it.mutableMethod.apply {
211+
val moveRegisterIndex = it.scanResult.patternScanResult!!.endIndex
212+
val viewRegister =
213+
getInstruction<OneRegisterInstruction>(moveRegisterIndex).registerA
214+
215+
val insertIndex = moveRegisterIndex + 1
216+
addInstruction(
217+
insertIndex,
218+
"invoke-static { v$viewRegister }, " +
219+
"$LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR->hideShowMoreButton(Landroid/view/View;)V"
220+
)
221+
}
222+
}
223+
224+
// endregion
206225
}
207226
}
+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.revanced.patches.youtube.layout.hide.loadmorebutton
1+
package app.revanced.patches.youtube.layout.hide.general
22

33
import app.revanced.patcher.data.ResourceContext
44
import app.revanced.patcher.patch.ResourcePatch
@@ -15,16 +15,10 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
1515
AddResourcesPatch::class
1616
]
1717
)
18-
internal object HideLoadMoreButtonResourcePatch : ResourcePatch() {
18+
internal object HideLayoutComponentsResourcePatch : ResourcePatch() {
1919
internal var expandButtonDownId: Long = -1
2020

2121
override fun execute(context: ResourceContext) {
22-
AddResourcesPatch(this::class)
23-
24-
SettingsPatch.PreferenceScreen.FEED.addPreferences(
25-
SwitchPreference("revanced_hide_load_more_button")
26-
)
27-
2822
expandButtonDownId = ResourceMappingPatch.resourceMappings.single {
2923
it.type == "layout" && it.name == "expand_button_down"
3024
}.id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package app.revanced.patches.youtube.layout.hide.general.fingerprints
2+
3+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsResourcePatch
4+
import app.revanced.util.patch.LiteralValueFingerprint
5+
import com.android.tools.smali.dexlib2.Opcode
6+
7+
internal object HideShowMoreButtonFingerprint : LiteralValueFingerprint(
8+
opcodes = listOf(
9+
Opcode.CONST,
10+
Opcode.CONST_4,
11+
Opcode.INVOKE_STATIC,
12+
Opcode.MOVE_RESULT_OBJECT
13+
),
14+
literalSupplier = { HideLayoutComponentsResourcePatch.expandButtonDownId }
15+
)
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,12 @@
11
package app.revanced.patches.youtube.layout.hide.loadmorebutton
22

3-
import app.revanced.util.exception
43
import app.revanced.patcher.data.BytecodeContext
5-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
6-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
74
import app.revanced.patcher.patch.BytecodePatch
8-
import app.revanced.patcher.patch.annotation.CompatiblePackage
9-
import app.revanced.patcher.patch.annotation.Patch
10-
import app.revanced.patches.youtube.layout.hide.loadmorebutton.fingerprints.HideLoadMoreButtonFingerprint
11-
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
5+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch
126

13-
@Patch(
14-
name = "Hide \'Load more\' button",
15-
description = "Adds an option to hide the button under videos that loads similar videos.",
16-
dependencies = [HideLoadMoreButtonResourcePatch::class],
17-
compatiblePackages = [
18-
CompatiblePackage(
19-
"com.google.android.youtube",
20-
[
21-
"18.32.39",
22-
"18.37.36",
23-
"18.38.44",
24-
"18.43.45",
25-
"18.44.41",
26-
"18.45.43",
27-
"18.48.39",
28-
"18.49.37",
29-
"19.01.34",
30-
"19.02.39",
31-
"19.03.36",
32-
"19.04.38",
33-
"19.05.36",
34-
"19.06.39",
35-
"19.07.40",
36-
"19.08.36",
37-
"19.09.37"
38-
]
39-
)
40-
]
41-
)
42-
@Suppress("unused")
7+
@Deprecated("This patch class has been merged into HideLayoutComponentsPatch.")
438
object HideLoadMoreButtonPatch : BytecodePatch(
44-
setOf(HideLoadMoreButtonFingerprint)
9+
dependencies = setOf(HideLayoutComponentsPatch::class)
4510
) {
46-
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
47-
"Lapp/revanced/integrations/youtube/patches/HideLoadMoreButtonPatch;"
48-
49-
override fun execute(context: BytecodeContext) {
50-
HideLoadMoreButtonFingerprint.result?.let {
51-
it.mutableMethod.apply {
52-
val moveRegisterIndex = it.scanResult.patternScanResult!!.endIndex
53-
val viewRegister =
54-
getInstruction<OneRegisterInstruction>(moveRegisterIndex).registerA
55-
56-
val insertIndex = moveRegisterIndex + 1
57-
addInstruction(
58-
insertIndex,
59-
"invoke-static { v$viewRegister }, " +
60-
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideLoadMoreButton(Landroid/view/View;)V"
61-
)
62-
}
63-
} ?: throw HideLoadMoreButtonFingerprint.exception
64-
}
65-
}
11+
override fun execute(context: BytecodeContext) {}
12+
}

src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/fingerprints/HideLoadMoreButtonFingerprint.kt

-15
This file was deleted.

src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import app.revanced.patches.youtube.layout.hide.shorts.fingerprints.*
1515
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1616
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
1717
import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch
18-
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
1918
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
2019
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
2120
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@@ -28,8 +27,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
2827
LithoFilterPatch::class,
2928
HideShortsComponentsResourcePatch::class,
3029
ResourceMappingPatch::class,
31-
NavigationBarHookPatch::class,
32-
PlayerTypeHookPatch::class
30+
NavigationBarHookPatch::class
3331
],
3432
compatiblePackages = [
3533
CompatiblePackage(

src/main/kotlin/app/revanced/patches/youtube/layout/thumbnails/AlternativeThumbnailsPatch.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.reques
2323
import app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.request.callback.OnSucceededFingerprint
2424
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
2525
import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch
26-
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
2726
import app.revanced.patches.youtube.misc.settings.SettingsPatch
2827
import app.revanced.util.resultOrThrow
2928
import com.android.tools.smali.dexlib2.AccessFlags
@@ -40,8 +39,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
4039
IntegrationsPatch::class,
4140
SettingsPatch::class,
4241
AddResourcesPatch::class,
43-
NavigationBarHookPatch::class,
44-
PlayerTypeHookPatch::class
42+
NavigationBarHookPatch::class
4543
],
4644
compatiblePackages = [
4745
CompatiblePackage(

src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import app.revanced.patcher.patch.annotation.Patch
1010
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
1111
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1212
import app.revanced.patches.youtube.misc.navigation.fingerprints.*
13+
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
1314
import app.revanced.util.getReference
1415
import app.revanced.util.indexOfFirstInstruction
1516
import app.revanced.util.resultOrThrow
@@ -25,6 +26,7 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
2526
dependencies = [
2627
IntegrationsPatch::class,
2728
NavigationBarHookResourcePatch::class,
29+
PlayerTypeHookPatch::class // Required to detect the search bar in all situations.
2830
],
2931
)
3032
@Suppress("unused")

src/main/resources/addresources/values/strings.xml

+5-7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
<string name="revanced_hide_search_result_recommendations_title">Hide \'People also watched\' recommendations</string>
8484
<string name="revanced_hide_search_result_recommendations_summary_on">Recommendations are hidden</string>
8585
<string name="revanced_hide_search_result_recommendations_summary_off">Recommendations are shown</string>
86+
<!-- 'Show more' should be translated with the same localized wording that YouTube displays.
87+
This button usually appears when searching for a YT creator. -->
88+
<string name="revanced_hide_show_more_button_title">Hide \'Show more\' button</string>
89+
<string name="revanced_hide_show_more_button_summary_on">Button is hidden</string>
90+
<string name="revanced_hide_show_more_button_summary_off">Button is shown</string>
8691
<string name="revanced_hide_timed_reactions_title">Hide timed reactions</string>
8792
<string name="revanced_hide_timed_reactions_summary_on">Timed reactions are hidden</string>
8893
<string name="revanced_hide_timed_reactions_summary_off">Timed reactions are shown</string>
@@ -507,13 +512,6 @@
507512
<string name="revanced_hide_info_cards_summary_on">Info cards are hidden</string>
508513
<string name="revanced_hide_info_cards_summary_off">Info cards are shown</string>
509514
</patch>
510-
<patch id="layout.hide.loadmorebutton.HideLoadMoreButtonResourcePatch">
511-
<!-- 'Load more' should be translated with the same localized wording that YouTube displays.
512-
This commonly appears when searching for a YT creator. -->
513-
<string name="revanced_hide_load_more_button_title">Hide \'Load More\' button</string>
514-
<string name="revanced_hide_load_more_button_summary_on">Button is hidden</string>
515-
<string name="revanced_hide_load_more_button_summary_off">Button is shown</string>
516-
</patch>
517515
<patch id="layout.hide.rollingnumber.DisableRollingNumberAnimationPatch">
518516
<string name="revanced_disable_rolling_number_animations_title">Disable rolling number animations</string>
519517
<string name="revanced_disable_rolling_number_animations_summary_on">Rolling numbers are not animated</string>

0 commit comments

Comments
 (0)