diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/fingerprints/PivotBarSetTextFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/fingerprints/PivotBarSetTextFingerprint.kt new file mode 100644 index 000000000..46c1d169d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/fingerprints/PivotBarSetTextFingerprint.kt @@ -0,0 +1,23 @@ +package app.revanced.patches.youtube.layout.navigation.label.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object PivotBarSetTextFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + parameters = listOf("L", "L", "L"), + opcodes = listOf( + Opcode.IPUT_OBJECT, + Opcode.INVOKE_DIRECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IPUT_OBJECT, + Opcode.MOVE_OBJECT, + Opcode.CHECK_CAST, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ), + customFingerprint = { it.name == "" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt new file mode 100644 index 000000000..75b9d8b11 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt @@ -0,0 +1,63 @@ +package app.revanced.patches.youtube.layout.navigation.label.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.navigation.label.fingerprints.PivotBarSetTextFingerprint +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.NAVIGATION +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction + +@Patch +@Name("hide-navigation-label") +@Description("Hide navigation bar labels.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class NavigationLabelPatch : BytecodePatch( + listOf( + PivotBarSetTextFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + PivotBarSetTextFingerprint.result?.let { + with (it.mutableMethod) { + val targetIndex = it.scanResult.patternScanResult!!.endIndex - 2 + val targetReference = (instruction(targetIndex) as ReferenceInstruction).reference.toString() + if (targetReference != "Landroid/widget/TextView;") + return PivotBarSetTextFingerprint.toErrorResult() + val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V" + ) + } + } ?: return PivotBarSetTextFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: NAVIGATION_SETTINGS", + "SETTINGS: HIDE_NAVIGATION_LABEL" + ) + ) + + SettingsPatch.updatePatchStatus("hide-navigation-label") + + return PatchResultSuccess() + } +} diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index e28e460ab..d1c2d228e 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -310,6 +310,9 @@ Please do not report any issues you encounter while using this feature."Latest posts are shown Latest posts are hidden Hide latest posts + Navigation label is shown + Navigation label is hidden + Hide navigation label Medical panels are shown Medical panels are hidden Hide medical panels diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 66f6db5d6..8c8140643 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -330,6 +330,9 @@ SETTINGS: HIDE_NAVIGATION_BUTTONS --> + + @@ -514,6 +517,7 @@ +