feat(YouTube - Hide layout components): Add "Hide view count" and "Hide upload time" settings (#5983)

This commit is contained in:
viSapio
2025-09-25 18:13:59 +05:30
committed by GitHub
parent 0ed7067459
commit 7a37d858fb
5 changed files with 127 additions and 2 deletions

View File

@@ -3,6 +3,9 @@ package app.revanced.extension.youtube.patches.components;
import static app.revanced.extension.youtube.shared.NavigationBar.NavigationButton;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
@@ -500,4 +503,62 @@ public final class LayoutComponentsFilter extends Filter {
// This check is important as the shelf layout is used for the library tab playlists.
return NavigationButton.getSelectedNavigationButton() != NavigationButton.LIBRARY;
}
/**
* Injection point.
*/
public static SpannableString modifyFeedSubtitleSpan(SpannableString original, float truncationDimension) {
try {
final boolean hideViewCount = Settings.HIDE_VIEW_COUNT.get();
final boolean hideUploadTime = Settings.HIDE_UPLOAD_TIME.get();
if (!hideViewCount && !hideUploadTime) {
return original;
}
// Applies only for these specific dimensions.
if (truncationDimension == 16f || truncationDimension == 42f) {
String delimiter = " · ";
final int delimiterLength = delimiter.length();
// Index includes the starting delimiter.
final int viewCountStartIndex = TextUtils.indexOf(original, delimiter);
if (viewCountStartIndex < 0) {
return original;
}
final int uploadTimeStartIndex = TextUtils.indexOf(original, delimiter,
viewCountStartIndex + delimiterLength);
if (uploadTimeStartIndex < 0) {
return original;
}
// Ensure there is exactly 2 delimiters.
if (TextUtils.indexOf(original, delimiter,
uploadTimeStartIndex + delimiterLength) >= 0) {
return original;
}
// Make a mutable copy that keeps existing span styling.
SpannableStringBuilder builder = new SpannableStringBuilder(original);
// Remove the sections.
if (hideUploadTime) {
builder.delete(uploadTimeStartIndex, original.length());
}
if (hideViewCount) {
builder.delete(viewCountStartIndex, uploadTimeStartIndex);
}
SpannableString replacement = new SpannableString(builder);
Logger.printDebug(() -> "Replacing feed subtitle span: " + original + " with: " + replacement);
return replacement;
}
} catch (Exception ex) {
Logger.printException(() -> "modifyFeedSubtitleSpan failure", ex);
}
return original;
}
}

View File

@@ -112,7 +112,9 @@ public class Settings extends BaseSettings {
public static final BooleanSetting HIDE_SHOW_MORE_BUTTON = new BooleanSetting("revanced_hide_show_more_button", TRUE, true);
public static final BooleanSetting HIDE_SURVEYS = new BooleanSetting("revanced_hide_surveys", TRUE);
public static final BooleanSetting HIDE_TICKET_SHELF = new BooleanSetting("revanced_hide_ticket_shelf", FALSE);
public static final BooleanSetting HIDE_UPLOAD_TIME = new BooleanSetting("revanced_hide_upload_time", FALSE, "revanced_hide_upload_time_user_dialog_message");
public static final BooleanSetting HIDE_VIDEO_RECOMMENDATION_LABELS = new BooleanSetting("revanced_hide_video_recommendation_labels", TRUE);
public static final BooleanSetting HIDE_VIEW_COUNT = new BooleanSetting("revanced_hide_view_count", FALSE, "revanced_hide_view_count_user_dialog_message");
// Alternative thumbnails
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_HOME = new EnumSetting<>("revanced_alt_thumbnail_home", ThumbnailOption.ORIGINAL);

View File

@@ -147,3 +147,17 @@ internal val showFloatingMicrophoneButtonFingerprint = fingerprint {
)
literal { fabButtonId }
}
internal val hideViewCountFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("Ljava/lang/CharSequence;")
opcodes(
Opcode.RETURN_OBJECT,
Opcode.CONST_STRING,
Opcode.RETURN_OBJECT,
)
strings(
"Has attachmentRuns but drawableRequester is missing.",
)
}

View File

@@ -36,6 +36,7 @@ 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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
var expandButtonDownId = -1L
private set
@@ -239,6 +240,8 @@ val hideLayoutComponentsPatch = bytecodePatch(
SwitchPreference("revanced_hide_surveys"),
SwitchPreference("revanced_hide_ticket_shelf"),
SwitchPreference("revanced_hide_video_recommendation_labels"),
SwitchPreference("revanced_hide_view_count"),
SwitchPreference("revanced_hide_upload_time"),
SwitchPreference("revanced_hide_doodles"),
)
@@ -397,6 +400,39 @@ val hideLayoutComponentsPatch = bytecodePatch(
// endregion
// region hide view count
hideViewCountFingerprint.method.apply {
val startIndex = hideViewCountFingerprint.patternMatch!!.startIndex
var returnStringRegister = getInstruction<OneRegisterInstruction>(startIndex).registerA
// Find the instruction where the text dimension is retrieved.
val applyDimensionIndex = indexOfFirstInstructionReversedOrThrow {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_STATIC &&
reference?.definingClass == "Landroid/util/TypedValue;" &&
reference.returnType == "F" &&
reference.name == "applyDimension" &&
reference.parameterTypes == listOf("I", "F", "Landroid/util/DisplayMetrics;")
}
// A float value is passed which is used to determine subtitle text size.
val floatDimensionRegister = getInstruction<OneRegisterInstruction>(
applyDimensionIndex + 1
).registerA
addInstructions(
applyDimensionIndex - 1,
"""
invoke-static { v$returnStringRegister, v$floatDimensionRegister }, $LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR->modifyFeedSubtitleSpan(Landroid/text/SpannableString;F)Landroid/text/SpannableString;
move-result-object v$returnStringRegister
"""
)
}
// endregion
// region hide filter bar
/**

View File

@@ -450,7 +450,6 @@ If a Doodle is currently showing in your region and this hide setting is on, the
<string name="revanced_hide_comments_thanks_button_title">Hide Thanks button</string>
<string name="revanced_hide_comments_thanks_button_summary_on">Thanks button is hidden</string>
<string name="revanced_hide_comments_thanks_button_summary_off">Thanks button is shown</string>
<string name="revanced_custom_filter_screen_title">Custom filter</string>
<string name="revanced_custom_filter_screen_summary">Hide components using custom filters</string>
<string name="revanced_custom_filter_title">Enable custom filter</string>
@@ -460,7 +459,20 @@ If a Doodle is currently showing in your region and this hide setting is on, the
<!-- 'Component path builder strings' is the technical name for identifying the Litho UI layout items to hide. This is an advanced feature and most users will never use this. -->
<string name="revanced_custom_filter_strings_summary">List of component path builder strings to filter separated by new line</string>
<string name="revanced_custom_filter_toast_invalid_syntax">Invalid custom filter: %s</string>
<string name="revanced_hide_view_count_title">Hide view count</string>
<string name="revanced_hide_view_count_summary_on">View count is hidden in feed and search results</string>
<string name="revanced_hide_view_count_summary_off">View count is shown in feed and search results</string>
<!-- Translations should lanaguge similar to revanced_hide_upload_time_user_dialog_message -->
<string name="revanced_hide_view_count_user_dialog_message">"Limitations:
• Shorts shelves, channel pages, and search results may still show view counts
• This feature does not work with automotive form factor"</string>
<string name="revanced_hide_upload_time_title">Hide upload time</string>
<string name="revanced_hide_upload_time_summary_on">Upload time is hidden in feed and search results</string>
<string name="revanced_hide_upload_time_summary_off">Upload time is shown in feed and search results</string>
<!-- Translations should lanaguge similar to revanced_hide_view_count_user_dialog_message -->
<string name="revanced_hide_upload_time_user_dialog_message">"Limitations:
• Shorts shelves, channel pages, and search results may still show upload times
• This feature does not work with automotive form factor"</string>
<string name="revanced_hide_keyword_content_screen_title">Hide keyword content</string>
<string name="revanced_hide_keyword_content_screen_summary">Hide feed and search videos using keyword filters</string>
<string name="revanced_hide_keyword_content_home_title">Hide Home videos by keywords</string>