Skip to content

Commit

Permalink
feat: hide-video-buttons patch
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 3, 2022
1 parent e78a801 commit bf82e02
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public Spliterator<BlockRule> spliterator() {

public final class LithoFilterPatch {
private static final Filter[] filters = new Filter[]{
new GeneralBytecodeAdsPatch()
new GeneralBytecodeAdsPatch(),
new ButtonsPatch()
};

public static boolean filter(final StringBuilder pathBuilder, final String identifier) {
Expand All @@ -132,6 +133,62 @@ public static boolean filter(final StringBuilder pathBuilder, final String ident
}
}

final class ButtonsPatch extends Filter {
private final BlockRule actionButtonsRule;
private final BlockRule dislikeRule;
private final BlockRule actionBarRule;

private final BlockRule[] rules;

public ButtonsPatch() {
BlockRule like = new BlockRule(SettingsEnum.HIDE_LIKE_BUTTON, "|like_button");
dislikeRule = new BlockRule(SettingsEnum.HIDE_DISLIKE_BUTTON, "dislike_button");
BlockRule download = new BlockRule(SettingsEnum.HIDE_DOWNLOAD_BUTTON, "download_button");
actionButtonsRule = new BlockRule(SettingsEnum.HIDE_ACTION_BUTTON, "ContainerType|video_action_button");
BlockRule playlist = new BlockRule(SettingsEnum.HIDE_PLAYLIST_BUTTON, "save_to_playlist_button");
rules = new BlockRule[]{like, dislikeRule, download, actionButtonsRule, playlist};

actionBarRule = new BlockRule(null, "video_action_bar");

this.register.registerAll(
like,
dislikeRule,
download,
playlist
);
}

private boolean hideActionBar() {
for (BlockRule rule : rules) if (!rule.isEnabled()) return false;
return true;
}

@Override
public boolean filter(final String path, final String identifier) {
if (hideActionBar() && actionBarRule.check(identifier).isBlocked()) return true;

var currentIsActionButton = actionButtonsRule.check(path).isBlocked();

if (dislikeRule.check(path).isBlocked()) ActionButton.doNotBlockCounter = 4;

if (currentIsActionButton && ActionButton.doNotBlockCounter-- > 0) {
if (SettingsEnum.HIDE_SHARE_BUTTON.getBoolean()) {
LogHelper.debug(ButtonsPatch.class, "Hiding share button");
return true;
} else return false;
}

if ((currentIsActionButton && ActionButton.doNotBlockCounter <= 0 && actionButtonsRule.isEnabled()) || Extensions.any(register, path)) {
LogHelper.debug(ButtonsPatch.class, "Blocked: " + path);
return true;
} else return false;
}

static class ActionButton {
public static int doNotBlockCounter = 4;
}
}

class GeneralBytecodeAdsPatch extends Filter {
private final BlockRule identifierBlock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public enum SettingsEnum {
ADREMOVER_SUGGESTIONS_REMOVAL("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN, true),
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN, true),
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN, true),
// Buttons
HIDE_LIKE_BUTTON("revanced_like_button", false, ReturnType.BOOLEAN, false),
HIDE_DISLIKE_BUTTON("revanced_dislike_button", false, ReturnType.BOOLEAN, false),
HIDE_DOWNLOAD_BUTTON("revanced_download_button", false, ReturnType.BOOLEAN, false),
HIDE_PLAYLIST_BUTTON("revanced_playlist_button", false, ReturnType.BOOLEAN, false),
HIDE_ACTION_BUTTON("revanced_action_button", false, ReturnType.BOOLEAN, false),
HIDE_SHARE_BUTTON("revanced_share_button", false, ReturnType.BOOLEAN, false),

//Layout settings
REEL_BUTTON_SHOWN("revanced_reel_button_enabled", false, ReturnType.BOOLEAN, true),
Expand Down

0 comments on commit bf82e02

Please sign in to comment.