Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube - Hide Shorts components): Hide like / dislike button in video ads #619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private static CharSequence onLithoTextLoaded(@NonNull Object conversionContext,
true, isRollingNumber);
} else if (!isRollingNumber && conversionContextString.contains("|shorts_dislike_button.eml|")) {
// Litho Shorts player.
if (!Settings.RYD_SHORTS.get()) {
if (!Settings.RYD_SHORTS.get() || Settings.HIDE_SHORTS_DISLIKE_BUTTON.get()) {
// Must clear the current video here, otherwise if the user opens a regular video
// then opens a litho short (while keeping the regular video on screen), then closes the short,
// the original video may show the incorrect dislike value.
Expand Down Expand Up @@ -451,7 +451,7 @@ public static boolean setShortsDislikes(@NonNull View likeDislikeView) {
if (!Settings.RYD_ENABLED.get()) {
return false;
}
if (!Settings.RYD_SHORTS.get()) {
if (!Settings.RYD_SHORTS.get() || Settings.HIDE_SHORTS_DISLIKE_BUTTON.get()) {
// Must clear the data here, in case a new video was loaded while PlayerType
// suggested the video was not a short (can happen when spoofing to an old app version).
clearData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import static app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar;
import app.revanced.integrations.youtube.shared.PlayerType;
Expand Down Expand Up @@ -310,6 +314,31 @@ public static void hideShortsShelf(final View shortsShelfView) {

// region Hide the buttons in older versions of YouTube. New versions use Litho.

private static void hideTextViewUnderCondition(BooleanSetting setting, View view) {
try {
if (setting.get()) {
TextView textView = (TextView) view;
ViewGroup.LayoutParams params = textView.getLayoutParams();
params.width = 0;
params.height = 0;
textView.setLayoutParams(params);
}
} catch (Exception ex) {
Logger.printException(() -> "hideTextViewUnderCondition failure", ex);
}
}

public static void hideLikeButton(final View likeButtonView) {
// Cannot simply set the visibility to gone for like/dislike,
// as some other unknown YT code also sets the visibility after this hook.
// Instead set the layout to a zero size.
hideTextViewUnderCondition(Settings.HIDE_SHORTS_LIKE_BUTTON, likeButtonView);
}

public static void hideDislikeButton(final View dislikeButtonView) {
hideTextViewUnderCondition(Settings.HIDE_SHORTS_DISLIKE_BUTTON, dislikeButtonView);
}

public static void hideShortsCommentsButton(final View commentsButtonView) {
hideViewUnderCondition(Settings.HIDE_SHORTS_COMMENTS_BUTTON, commentsButtonView);
}
Expand Down
Loading