From e6411d946ab4cc71bfcd11509d058933e45819b7 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 26 Apr 2024 07:59:28 +0900 Subject: [PATCH] feat(YouTube/Hide feed components): add `Channel tab filter` settings --- .../feed/components/FeedComponentsPatch.kt | 50 +++++++++++++++++++ .../ChannelTabBuilderFingerprint.kt | 11 ++++ .../ChannelTabRendererFingerprint.kt | 12 +++++ .../ScrollTopParentFingerprint.kt | 2 +- .../DoubleBackToClosePatch.kt | 2 +- .../youtube/settings/host/values/strings.xml | 8 +++ .../youtube/settings/xml/revanced_prefs.xml | 2 + 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabBuilderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabRendererFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/utils/{fix/doublebacktoclose/fingerprint => fingerprints}/ScrollTopParentFingerprint.kt (90%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt index 41775a68a..426f02db9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt @@ -13,6 +13,8 @@ import app.revanced.patches.youtube.feed.components.fingerprints.BreakingNewsFin import app.revanced.patches.youtube.feed.components.fingerprints.ChannelListSubMenuFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ChannelListSubMenuTabletFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ChannelListSubMenuTabletSyntheticFingerprint +import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabBuilderFingerprint +import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabRendererFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserParentFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.FilterBarHeightFingerprint @@ -20,6 +22,7 @@ import app.revanced.patches.youtube.feed.components.fingerprints.LatestVideosBut import app.revanced.patches.youtube.feed.components.fingerprints.RelatedChipCloudFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.SearchResultsChipBarFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ShowMoreButtonFingerprint +import app.revanced.patches.youtube.utils.fingerprints.ScrollTopParentFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.FEED_CLASS_DESCRIPTOR @@ -27,10 +30,13 @@ import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.getTargetIndex +import app.revanced.util.getTargetIndexReversed +import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -52,10 +58,12 @@ object FeedComponentsPatch : BaseBytecodePatch( ChannelListSubMenuFingerprint, ChannelListSubMenuTabletFingerprint, ChannelListSubMenuTabletSyntheticFingerprint, + ChannelTabRendererFingerprint, ElementParserParentFingerprint, FilterBarHeightFingerprint, LatestVideosButtonFingerprint, RelatedChipCloudFingerprint, + ScrollTopParentFingerprint, SearchResultsChipBarFingerprint, ShowMoreButtonFingerprint ) @@ -197,6 +205,48 @@ object FeedComponentsPatch : BaseBytecodePatch( // endregion + // region patch for hide channel tab + + ChannelTabBuilderFingerprint.resolve( + context, + ScrollTopParentFingerprint.resultOrThrow().classDef + ) + + val channelTabBuilderMethod = ChannelTabBuilderFingerprint.resultOrThrow().mutableMethod + + ChannelTabRendererFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val iteratorIndex = getTargetIndexWithMethodReferenceName("hasNext") + val iteratorRegister = getInstruction(iteratorIndex).registerC + + val targetIndex = indexOfFirstInstruction { + val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) + + opcode == Opcode.INVOKE_INTERFACE + && reference?.returnType == channelTabBuilderMethod.returnType + && reference.parameterTypes == channelTabBuilderMethod.parameterTypes + } + + val objectIndex = getTargetIndexReversed(targetIndex, Opcode.IGET_OBJECT) + val objectInstruction = getInstruction(objectIndex) + val objectReference = getInstruction(objectIndex).reference + + addInstructionsWithLabels( + objectIndex + 1, """ + invoke-static {v${objectInstruction.registerA}}, $FEED_CLASS_DESCRIPTOR->hideChannelTab(Ljava/lang/String;)Z + move-result v${objectInstruction.registerA} + if-eqz v${objectInstruction.registerA}, :ignore + invoke-interface {v$iteratorRegister}, Ljava/util/Iterator;->remove()V + goto :next_iterator + :ignore + iget-object v${objectInstruction.registerA}, v${objectInstruction.registerB}, $objectReference + """, ExternalLabel("next_iterator", getInstruction(iteratorIndex)) + ) + } + } + + // endregion + LithoFilterPatch.addFilter(FEED_COMPONENTS_FILTER_CLASS_DESCRIPTOR) LithoFilterPatch.addFilter(FEED_VIDEO_FILTER_CLASS_DESCRIPTOR) LithoFilterPatch.addFilter(FEED_VIDEO_VIEWS_FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabBuilderFingerprint.kt new file mode 100644 index 000000000..45dcbe156 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabBuilderFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.feed.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ChannelTabBuilderFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/CharSequence;", "Ljava/lang/CharSequence;", "Z", "L") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabRendererFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabRendererFingerprint.kt new file mode 100644 index 000000000..c952668d8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelTabRendererFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.feed.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ChannelTabRendererFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "Ljava/util/List;", "I"), + strings = listOf("TabRenderer.content contains SectionListRenderer but the tab does not have a section list controller.") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ScrollTopParentFingerprint.kt similarity index 90% rename from src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ScrollTopParentFingerprint.kt index e80b99545..859d619f9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ScrollTopParentFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint +package app.revanced.patches.youtube.utils.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt index 0803f53b1..634b57346 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt @@ -5,9 +5,9 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.youtube.utils.fingerprints.ScrollTopParentFingerprint import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollPositionFingerprint import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopFingerprint -import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopParentFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch import app.revanced.util.getWalkerMethod diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 5a47ff665..aee5db8a8 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -149,6 +149,14 @@ Tap here to learn more about DeArrow." Channel profile Hide or show components in the channel profile. + Enable channel tab filter + Channel tab filter is enabled. + Channel tab filter is disabled. + Channel tab filter + List of channel tab names to filter separated by a new line. + "Shorts +Playlists +Store" Hide browse store button Browse store button is hidden. Browse store button is shown. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 8b114f5ad..f8a94f9e9 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -42,6 +42,8 @@ + +