Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
feat(YouTube - Hide Shorts components): Hide tagged products, hide se…
Browse files Browse the repository at this point in the history
…arch suggestions (#615)
  • Loading branch information
LisoUseInAIKyrios authored Apr 14, 2024
1 parent 79a3a44 commit 0586fb7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* All saved JSON text is converted to lowercase to keep the output less obnoxious.
*/
@SuppressWarnings("unused")
public class EnumSetting<T extends Enum> extends Setting<T> {
public class EnumSetting<T extends Enum<?>> extends Setting<T> {
public EnumSetting(String key, T defaultValue) {
super(key, defaultValue);
}
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void writeToJSON(JSONObject json, String importExportKey) throws JSONE
@NonNull
private T getEnumFromString(String enumName) {
//noinspection ConstantConditions
for (Enum value : defaultValue.getClass().getEnumConstants()) {
for (Enum<?> value : defaultValue.getClass().getEnumConstants()) {
if (value.name().equalsIgnoreCase(enumName)) {
// noinspection unchecked
return (T) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void saveBoolean(@NonNull String key, boolean value) {
/**
* @param value a NULL parameter removes the value from the preferences
*/
public void saveEnumAsString(@NonNull String key, @Nullable Enum value) {
public void saveEnumAsString(@NonNull String key, @Nullable Enum<?> value) {
saveObjectAsString(key, value);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public String getString(@NonNull String key, @NonNull String _default) {
}

@NonNull
public <T extends Enum> T getEnum(@NonNull String key, @NonNull T _default) {
public <T extends Enum<?>> T getEnum(@NonNull String key, @NonNull T _default) {
Objects.requireNonNull(_default);
try {
String enumName = preferences.getString(key, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ public final class ShortsFilter extends Filter {
private final StringFilterGroup shortsCompactFeedVideoPath;
private final ByteArrayFilterGroup shortsCompactFeedVideoBuffer;

private final StringFilterGroup channelBar;
private final StringFilterGroup fullVideoLinkLabel;
private final StringFilterGroup videoTitle;
private final StringFilterGroup reelSoundMetadata;
private final StringFilterGroup subscribeButton;
private final StringFilterGroup subscribeButtonPaused;
private final StringFilterGroup soundButton;
private final StringFilterGroup infoPanel;
private final StringFilterGroup joinButton;
private final StringFilterGroup shelfHeader;

private final StringFilterGroup suggestedActionPath;
private final ByteArrayFilterGroupList suggestedActions = new ByteArrayFilterGroupList();
private final StringFilterGroup suggestedAction;
private final ByteArrayFilterGroupList suggestedActionsGroupList = new ByteArrayFilterGroupList();

private final StringFilterGroup actionBar;
private final ByteArrayFilterGroupList videoActionButtonGroupList = new ByteArrayFilterGroupList();
Expand All @@ -44,29 +37,23 @@ public ShortsFilter() {
// Identifier components.
//

var shorts = new StringFilterGroup(
var shortsIdentifiers = new StringFilterGroup(
null, // Setting is based on navigation state.
"shorts_shelf",
"inline_shorts",
"shorts_grid",
"shorts_video_cell",
"shorts_pivot_item"
);

// Feed Shorts shelf header.
// Use a different filter group for this pattern, as it requires an additional check after matching.
shelfHeader = new StringFilterGroup(
null,
"shelf_header.eml"
);

// Home / subscription feed components.

var thanksButton = new StringFilterGroup( // Edit: Does this item show up anymore?
Settings.HIDE_SHORTS_THANKS_BUTTON,
"suggested_action"
);

addIdentifierCallbacks(shorts, shelfHeader, thanksButton);
addIdentifierCallbacks(shortsIdentifiers, shelfHeader);

//
// Path components.
Expand All @@ -80,119 +67,122 @@ public ShortsFilter() {
shortsCompactFeedVideoBuffer = new ByteArrayFilterGroup(null, "/frame0.jpg");

// Shorts player components.
joinButton = new StringFilterGroup(
Settings.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);

subscribeButton = new StringFilterGroup(
Settings.HIDE_SHORTS_SUBSCRIBE_BUTTON,
"subscribe_button"
);

subscribeButtonPaused = new StringFilterGroup(
Settings.HIDE_SHORTS_SUBSCRIBE_BUTTON_PAUSED,
StringFilterGroup pausedOverlayButtons = new StringFilterGroup(
Settings.HIDE_SHORTS_PAUSED_OVERLAY_BUTTONS,
"shorts_paused_state"
);

channelBar = new StringFilterGroup(
StringFilterGroup channelBar = new StringFilterGroup(
Settings.HIDE_SHORTS_CHANNEL_BAR,
REEL_CHANNEL_BAR_PATH
);

fullVideoLinkLabel = new StringFilterGroup(
StringFilterGroup fullVideoLinkLabel = new StringFilterGroup(
Settings.HIDE_SHORTS_FULL_VIDEO_LINK_LABEL,
"reel_multi_format_link"
);

videoTitle = new StringFilterGroup(
StringFilterGroup videoTitle = new StringFilterGroup(
Settings.HIDE_SHORTS_VIDEO_TITLE,
"shorts_video_title_item"
);

reelSoundMetadata = new StringFilterGroup(
StringFilterGroup reelSoundMetadata = new StringFilterGroup(
Settings.HIDE_SHORTS_SOUND_METADATA_LABEL,
"reel_sound_metadata"
);

soundButton = new StringFilterGroup(
StringFilterGroup soundButton = new StringFilterGroup(
Settings.HIDE_SHORTS_SOUND_BUTTON,
"reel_pivot_button"
);

infoPanel = new StringFilterGroup(
StringFilterGroup infoPanel = new StringFilterGroup(
Settings.HIDE_SHORTS_INFO_PANEL,
"shorts_info_panel_overview"
);

joinButton = new StringFilterGroup(
Settings.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);

subscribeButton = new StringFilterGroup(
Settings.HIDE_SHORTS_SUBSCRIBE_BUTTON,
"subscribe_button"
);

actionBar = new StringFilterGroup(
null,
"shorts_action_bar"
);

suggestedActionPath = new StringFilterGroup(
suggestedAction = new StringFilterGroup(
null,
"suggested_action.eml"
);

addPathCallbacks(
shortsCompactFeedVideoPath,
joinButton, subscribeButton, subscribeButtonPaused, suggestedActionPath,
channelBar, fullVideoLinkLabel, videoTitle, reelSoundMetadata,
soundButton, infoPanel, actionBar
shortsCompactFeedVideoPath, suggestedAction, actionBar, joinButton, subscribeButton,
pausedOverlayButtons, channelBar, fullVideoLinkLabel, videoTitle, reelSoundMetadata,
soundButton, infoPanel
);

//
// Action buttons
//
var shortsLikeButton = new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_LIKE_BUTTON,
"shorts_like_button"
);

var shortsDislikeButton = new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_DISLIKE_BUTTON,
"shorts_dislike_button"
);

var shortsCommentButton = new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_COMMENTS_BUTTON,
"reel_comment_button"
);

var shortsShareButton = new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_SHARE_BUTTON,
"reel_share_button"
);

var shortsRemixButton = new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_REMIX_BUTTON,
"reel_remix_button"
);

videoActionButtonGroupList.addAll(
shortsLikeButton,
shortsDislikeButton,
shortsCommentButton,
shortsShareButton,
shortsRemixButton
// This also appears as the path item 'shorts_like_button.eml'
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_LIKE_BUTTON,
"reel_like_button",
"reel_like_toggled_button"
),
// This also appears as the path item 'shorts_dislike_button.eml'
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_DISLIKE_BUTTON,
"reel_dislike_button",
"reel_dislike_toggled_button"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_COMMENTS_BUTTON,
"reel_comment_button"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_SHARE_BUTTON,
"reel_share_button"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_REMIX_BUTTON,
"reel_remix_button"
)
);

//
// Suggested actions.
//
suggestedActions.addAll(
suggestedActionsGroupList.addAll(
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_SHOP_BUTTON,
"yt_outline_bag_"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_LOCATION_BUTTON,
Settings.HIDE_SHORTS_TAGGED_PRODUCTS,
// Product buttons show pictures of the products, and does not have any unique icons to identify.
// Instead use a unique identifier found in the buffer.
"PAproduct_listZ"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_LOCATION_LABEL,
"yt_outline_location_point_"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_SAVE_SOUND_BUTTON,
"yt_outline_list_add_"
),
new ByteArrayFilterGroup(
Settings.HIDE_SHORTS_SEARCH_SUGGESTIONS,
"yt_outline_search_"
)
);
}
Expand All @@ -201,15 +191,15 @@ public ShortsFilter() {
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
if (contentType == FilterContentType.PATH) {
// Always filter if matched.
if (matchedGroup == soundButton ||
matchedGroup == infoPanel ||
matchedGroup == channelBar ||
matchedGroup == fullVideoLinkLabel ||
matchedGroup == videoTitle ||
matchedGroup == reelSoundMetadata ||
matchedGroup == subscribeButtonPaused
) return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
if (matchedGroup == subscribeButton || matchedGroup == joinButton) {
// Filter only when reelChannelBar is visible to avoid false positives.
if (path.startsWith(REEL_CHANNEL_BAR_PATH)) {
return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
}
return false;
}

if (matchedGroup == shortsCompactFeedVideoPath) {
if (shouldHideShortsFeedItems() && contentIndex == 0
Expand All @@ -219,32 +209,27 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
return false;
}

if (matchedGroup == subscribeButton || matchedGroup == joinButton) {
// Filter only when reelChannelBar is visible to avoid false positives.
if (path.startsWith(REEL_CHANNEL_BAR_PATH)) return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
return false;
}

// Video action buttons (like, dislike, comment, share, remix) have the same path.
if (matchedGroup == actionBar) {
if (videoActionButtonGroupList.check(protobufBufferArray).isFiltered()) return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
if (videoActionButtonGroupList.check(protobufBufferArray).isFiltered()) {
return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
}
return false;
}

if (matchedGroup == suggestedActionPath) {
if (contentIndex == 0 && suggestedActions.check(protobufBufferArray).isFiltered()) return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
// else, return false;
if (matchedGroup == suggestedAction) {
if (contentIndex == 0 && suggestedActionsGroupList.check(protobufBufferArray).isFiltered()) {
return super.isFiltered(
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
);
}
return false;
}

return false;
} else {
// Feed/search path components.
// Feed/search identifier components.
if (matchedGroup == shelfHeader) {
// Because the header is used in watch history and possibly other places, check for the index,
// which is 0 when the shelf header is used for Shorts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ public class Settings extends BaseSettings {
public static final BooleanSetting HIDE_SHORTS_SEARCH = new BooleanSetting("revanced_hide_shorts_search", FALSE);
public static final BooleanSetting HIDE_SHORTS_JOIN_BUTTON = new BooleanSetting("revanced_hide_shorts_join_button", TRUE);
public static final BooleanSetting HIDE_SHORTS_SUBSCRIBE_BUTTON = new BooleanSetting("revanced_hide_shorts_subscribe_button", TRUE);
public static final BooleanSetting HIDE_SHORTS_SUBSCRIBE_BUTTON_PAUSED = new BooleanSetting("revanced_hide_shorts_subscribe_button_paused", FALSE);
public static final BooleanSetting HIDE_SHORTS_THANKS_BUTTON = new BooleanSetting("revanced_hide_shorts_thanks_button", TRUE);
public static final BooleanSetting HIDE_SHORTS_PAUSED_OVERLAY_BUTTONS = new BooleanSetting("revanced_hide_shorts_paused_overlay_buttons", FALSE);
public static final BooleanSetting HIDE_SHORTS_SHOP_BUTTON = new BooleanSetting("revanced_hide_shorts_shop_button", TRUE);
public static final BooleanSetting HIDE_SHORTS_LOCATION_BUTTON = new BooleanSetting("revanced_hide_shorts_location_button", FALSE);
public static final BooleanSetting HIDE_SHORTS_TAGGED_PRODUCTS = new BooleanSetting("revanced_hide_shorts_tagged_products", TRUE);
public static final BooleanSetting HIDE_SHORTS_LOCATION_LABEL = new BooleanSetting("revanced_hide_shorts_location_label", FALSE);
public static final BooleanSetting HIDE_SHORTS_SAVE_SOUND_BUTTON = new BooleanSetting("revanced_hide_shorts_save_sound_button", FALSE);
public static final BooleanSetting HIDE_SHORTS_SEARCH_SUGGESTIONS = new BooleanSetting("revanced_hide_shorts_search_suggestions", FALSE);
public static final BooleanSetting HIDE_SHORTS_LIKE_BUTTON = new BooleanSetting("revanced_hide_shorts_like_button", FALSE);
public static final BooleanSetting HIDE_SHORTS_DISLIKE_BUTTON = new BooleanSetting("revanced_hide_shorts_dislike_button", FALSE);
public static final BooleanSetting HIDE_SHORTS_COMMENTS_BUTTON = new BooleanSetting("revanced_hide_shorts_comments_button", FALSE);
Expand Down

0 comments on commit 0586fb7

Please sign in to comment.