|
| 1 | +package app.revanced.patches.youtube.layout.hide.relatedvideooverlay |
| 2 | + |
| 3 | +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels |
| 4 | +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction |
| 5 | +import app.revanced.patcher.patch.bytecodePatch |
| 6 | +import app.revanced.patcher.patch.resourcePatch |
| 7 | +import app.revanced.patches.all.misc.resources.addResources |
| 8 | +import app.revanced.patches.all.misc.resources.addResourcesPatch |
| 9 | +import app.revanced.patches.shared.misc.mapping.get |
| 10 | +import app.revanced.patches.shared.misc.mapping.resourceMappingPatch |
| 11 | +import app.revanced.patches.shared.misc.mapping.resourceMappings |
| 12 | +import app.revanced.patches.shared.misc.settings.preference.SwitchPreference |
| 13 | +import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch |
| 14 | +import app.revanced.patches.youtube.misc.settings.PreferenceScreen |
| 15 | +import app.revanced.patches.youtube.misc.settings.settingsPatch |
| 16 | +import app.revanced.patcher.util.smali.ExternalLabel |
| 17 | + |
| 18 | +internal var appRelatedEndScreenResults = -1L |
| 19 | + private set |
| 20 | + |
| 21 | +private val hideRelatedVideoOverlayResourcePatch = resourcePatch { |
| 22 | + dependsOn( |
| 23 | + resourceMappingPatch, |
| 24 | + ) |
| 25 | + |
| 26 | + execute { |
| 27 | + appRelatedEndScreenResults = resourceMappings[ |
| 28 | + "layout", |
| 29 | + "app_related_endscreen_results", |
| 30 | + ] |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +private const val EXTENSION_CLASS_DESCRIPTOR = |
| 35 | + "Lapp/revanced/extension/youtube/patches/HideRelatedVideoOverlayPatch;" |
| 36 | + |
| 37 | +@Suppress("unused") |
| 38 | +val hideRelatedVideoOverlayPatch = bytecodePatch( |
| 39 | + name = "Hide related video overlay", |
| 40 | + description = "Adds an option to hide the related video overlay shown when swiping up in fullscreen.", |
| 41 | +) { |
| 42 | + dependsOn( |
| 43 | + settingsPatch, |
| 44 | + sharedExtensionPatch, |
| 45 | + addResourcesPatch, |
| 46 | + hideRelatedVideoOverlayResourcePatch, |
| 47 | + ) |
| 48 | + |
| 49 | + compatibleWith( |
| 50 | + "com.google.android.youtube"( |
| 51 | + "19.16.39", |
| 52 | + "19.25.37", |
| 53 | + "19.34.42", |
| 54 | + "19.43.41", |
| 55 | + "19.47.53", |
| 56 | + "20.07.39", |
| 57 | + "20.12.46", |
| 58 | + ) |
| 59 | + ) |
| 60 | + |
| 61 | + execute { |
| 62 | + addResources("youtube", "layout.hide.relatedvideooverlay.hideRelatedVideoOverlayPatch") |
| 63 | + |
| 64 | + PreferenceScreen.PLAYER.addPreferences( |
| 65 | + SwitchPreference("revanced_hide_related_video_overlay") |
| 66 | + ) |
| 67 | + |
| 68 | + relatedEndScreenResultsFingerprint.match( |
| 69 | + relatedEndScreenResultsParentFingerprint.originalClassDef |
| 70 | + ).method.apply { |
| 71 | + addInstructionsWithLabels( |
| 72 | + 0, |
| 73 | + """ |
| 74 | + invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideRelatedVideoOverlay()Z |
| 75 | + move-result v0 |
| 76 | + if-eqz v0, :show |
| 77 | + return-void |
| 78 | + """, |
| 79 | + ExternalLabel("show", getInstruction(0)) |
| 80 | + ) |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments