add hide-player-button-background patch

This commit is contained in:
inotia00
2023-02-18 14:26:45 +09:00
parent 018323201b
commit b9931deca4
3 changed files with 67 additions and 50 deletions

View File

@ -0,0 +1,10 @@
package app.revanced.patches.youtube.layout.player.playerbuttonbg.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object HidePlayerButtonFingerprint : MethodFingerprint (
customFingerprint = {
it.definingClass == "Lapp/revanced/integrations/patches/layout/PlayerLayoutPatch;"
&& it.name == "hidePlayerButton"
}
)

View File

@ -0,0 +1,57 @@
package app.revanced.patches.youtube.layout.player.playerbuttonbg.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.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.player.playerbuttonbg.fingerprints.HidePlayerButtonFingerprint
import app.revanced.patches.youtube.misc.playerbutton.patch.PlayerButtonPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
@Patch
@Name("hide-player-button-background")
@Description("Hide player button background.")
@DependsOn(
[
PlayerButtonPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HidePlayerButtonBackgroundPatch : BytecodePatch(
listOf(
HidePlayerButtonFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
HidePlayerButtonFingerprint.result?.mutableMethod?.addInstruction(
0,
"invoke-static { p0 }, Lapp/revanced/integrations/utils/ResourceHelper;->hidePlayerButtonBackground(Landroid/view/View;)V"
) ?: return HidePlayerButtonFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: OTHER_LAYOUT_SETTINGS",
"PREFERENCE_HEADER: PLAYER",
"SETTINGS: HIDE_PLAYER_BUTTON_BACKGROUND"
)
)
SettingsPatch.updatePatchStatus("hide-player-button-background")
return PatchResultSuccess()
}
}

View File

@ -1,50 +0,0 @@
package app.revanced.patches.youtube.misc.playerbuttonoverlay.patch
import app.revanced.extensions.doRecursively
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
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.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper
import org.w3c.dom.Element
@Patch
@Name("remove-player-button-background")
@Description("Removes the background from the video player buttons.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class PlayerButtonOverlayPatch : ResourcePatch {
private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml"
val replacements = arrayOf(
"color"
)
}
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
editor.file.doRecursively { node ->
replacements.forEach replacement@{ replacement ->
if (node !is Element) return@replacement
node.getAttributeNode("android:$replacement")?.let { attribute ->
attribute.textContent = "@android:color/transparent"
}
}
}
}
SettingsPatch.updatePatchStatus("remove-player-button-background")
return PatchResultSuccess()
}
}