feat(youtube): add hide-load-more-button patch

This commit is contained in:
inotia00 2023-05-08 09:26:56 +09:00
parent b4b6a6cf8a
commit 6af1b8b762
5 changed files with 93 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package app.revanced.patches.youtube.layout.general.loadmorebutton.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object LoadMoreButtonFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.CONST_4,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any { instruction ->
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
(instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.expandButtonId
} == true
}
)

View File

@ -0,0 +1,64 @@
package app.revanced.patches.youtube.layout.general.loadmorebutton.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.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.loadmorebutton.fingerprints.LoadMoreButtonFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("hide-load-more-button")
@Description("Hides the button under videos that loads similar videos.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class,
]
)
@YouTubeCompatibility
@Version("0.0.1")
class LoadMoreButtonPatch : BytecodePatch(
listOf(
LoadMoreButtonFingerprint,
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LoadMoreButtonFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $GENERAL->hideLoadMoreButton(Landroid/view/View;)V"
)
}
}?: return LoadMoreButtonFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_SETTINGS",
"SETTINGS: HIDE_LOAD_MORE_BUTTON"
)
)
SettingsPatch.updatePatchStatus("hide-load-more-button")
return PatchResultSuccess()
}
}

View File

@ -125,7 +125,7 @@ class SettingsPatch : AbstractSettingsResourcePatch(
return PatchResultSuccess()
}
companion object {
private lateinit var contexts: ResourceContext
internal lateinit var contexts: ResourceContext
internal fun addPreference(settingArray: Array<String>) {
contexts.addPreference(settingArray)

View File

@ -316,6 +316,9 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_hide_library_button_summary_off">Library button is shown</string>
<string name="revanced_hide_library_button_summary_on">Library button is hidden</string>
<string name="revanced_hide_library_button_title">Hide library button</string>
<string name="revanced_hide_load_more_button_summary_off">Load more button is shown</string>
<string name="revanced_hide_load_more_button_summary_on">Load more button is hidden</string>
<string name="revanced_hide_load_more_button_title">Hide load more button</string>
<string name="revanced_hide_navigation_label_summary_off">Navigation label is shown</string>
<string name="revanced_hide_navigation_label_summary_on">Navigation label is hidden</string>
<string name="revanced_hide_navigation_label_title">Hide navigation label</string>

View File

@ -141,6 +141,9 @@
<!-- SETTINGS: HIDE_BREAKING_NEWS_SHELF
<SwitchPreference android:title="@string/revanced_hide_breaking_news_shelf_title" android:key="revanced_hide_breaking_news_shelf" android:defaultValue="false" android:summaryOn="@string/revanced_hide_breaking_news_shelf_summary_on" android:summaryOff="@string/revanced_hide_breaking_news_shelf_summary_off" />SETTINGS: HIDE_BREAKING_NEWS_SHELF -->
<!-- SETTINGS: HIDE_LOAD_MORE_BUTTON
<SwitchPreference android:title="@string/revanced_hide_load_more_button_title" android:key="revanced_hide_load_more_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_load_more_button_summary_on" android:summaryOff="@string/revanced_hide_load_more_button_summary_off" />SETTINGS: HIDE_LOAD_MORE_BUTTON -->
<!-- SETTINGS: HIDE_ACCOUNT_MENU
<SwitchPreference android:title="@string/revanced_hide_account_menu_title" android:key="revanced_hide_account_menu" android:defaultValue="false" android:summaryOn="@string/revanced_hide_account_menu_summary_on" android:summaryOff="@string/revanced_hide_account_menu_summary_off" />
<EditTextPreference android:title="@string/revanced_account_menu_custom_filter_title" android:key="revanced_account_menu_custom_filter" android:summary="@string/revanced_account_menu_custom_filter_summary" android:defaultValue="YouTube Music,YouTube Kids" android:inputType="text" android:dependency="revanced_hide_account_menu" />SETTINGS: HIDE_ACCOUNT_MENU -->
@ -482,6 +485,7 @@
<Preference android:title="hide-category-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-channel-avatar-section" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-breaking-news-shelf" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-load-more-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-account-menu" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="header-switch" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>