Skip to content

Commit

Permalink
feat(youtube): add hide-latest-videos-button patch
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Aug 3, 2023
1 parent 350e516 commit ab663b8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.revanced.patches.youtube.general.latestvideosbutton.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.Bar
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

object LatestVideosButtonFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Z"),
opcodes = listOf(
Opcode.CONST,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(Bar) }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package app.revanced.patches.youtube.general.latestvideosbutton.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.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
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.general.latestvideosbutton.fingerprints.LatestVideosButtonFingerprint
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch
@Name("Hide latest videos button")
@Description("Hides latest videos button in home feed.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class,
]
)
@YouTubeCompatibility
@Version("0.0.1")
class LatestVideosButtonPatch : BytecodePatch(
listOf(LatestVideosButtonFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
LatestVideosButtonFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA

addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $GENERAL->hideLatestVideosButton(Landroid/view/View;)V"
)
}
} ?: return LatestVideosButtonFingerprint.toErrorResult()

/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_SETTINGS",
"SETTINGS: HIDE_LATEST_VIDEOS_BUTTON"
)
)

SettingsPatch.updatePatchStatus("hide-latest-videos-button")

return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SharedResourceIdPatch : ResourcePatch {
var AutoNavPreviewStub: Long = -1
var AutoNavToggle: Long = -1
var BackgroundCategory: Long = -1
var Bar: Long = -1
var BarContainerHeight: Long = -1
var BottomPanelOverlayText: Long = -1
var BottomSheetMargins: Long = -1
Expand Down Expand Up @@ -101,6 +102,7 @@ class SharedResourceIdPatch : ResourcePatch {
AutoNavPreviewStub = find(ID, "autonav_preview_stub")
AutoNavToggle = find(ID, "autonav_toggle")
BackgroundCategory = find(STRING, "pref_background_and_offline_category")
Bar = find(LAYOUT, "bar")
BarContainerHeight = find(DIMEN, "bar_container_height")
BottomPanelOverlayText = find(ID, "bottom_panel_overlay_text")
BottomSheetMargins = find(DIMEN, "bottom_sheet_margins")
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/youtube/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
<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_latest_videos_button_summary_off">Latest videos button is shown</string>
<string name="revanced_hide_latest_videos_button_summary_on">Latest videos button is hidden</string>
<string name="revanced_hide_latest_videos_button_title">Hide latest videos 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>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
<!-- SETTINGS: HIDE_FLOATING_MICROPHONE
<SwitchPreference android:title="@string/revanced_hide_floating_microphone_title" android:key="revanced_hide_floating_microphone" android:defaultValue="true" android:summaryOn="@string/revanced_hide_floating_microphone_summary_on" android:summaryOff="@string/revanced_hide_floating_microphone_summary_off" />SETTINGS: HIDE_FLOATING_MICROPHONE -->

<!-- SETTINGS: HIDE_LATEST_VIDEOS_BUTTON
<SwitchPreference android:title="@string/revanced_hide_latest_videos_button_title" android:key="revanced_hide_latest_videos_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_latest_videos_button_summary_on" android:summaryOff="@string/revanced_hide_latest_videos_button_summary_off" />SETTINGS: HIDE_LATEST_VIDEOS_BUTTON -->

<!-- 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 -->

Expand Down Expand Up @@ -326,6 +329,7 @@
<Preference android:title="hide-email-address" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-floating-microphone" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-layout-components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-latest-videos-button" 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-mix-playlists" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-snack-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
Expand Down

0 comments on commit ab663b8

Please sign in to comment.