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

Confirmation before connecting to youtube.com/youtu.be #4826

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

unlxam
Copy link

@unlxam unlxam commented Aug 10, 2024

Closes #4798

I also thought that since we are adding a confirmation before going to youtube.com/youtu.be in the "Watch on YouTube (Embed)" and "[YT]" in the comments. It would make sense adding also to external domains from links in the description and comments too. What you think about that?

@unlxam unlxam requested a review from a team as a code owner August 10, 2024 21:43
@unlxam unlxam requested review from SamantazFox and removed request for a team August 10, 2024 21:43
src/invidious/routes/misc.cr Outdated Show resolved Hide resolved
<% end %>

<div class="h-box">
<h3><%= translate(locale, "You are leaving Invidious. Continue to external link?") %></h3>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add this line to locales/en-US.json, otherwise Weblate won't be able to detect it, and in turn that won't be proposed to translators:

"confirm_dialog_external_link": "You are leaving Invidious. Continue to external link?"
Suggested change
<h3><%= translate(locale, "You are leaving Invidious. Continue to external link?") %></h3>
<h3><%= translate(locale, "confirm_dialog_external_link") %></h3>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the suggestion I made above! You need to use confirm_dialog_external_link, not the translated string here!

src/invidious/frontend/comments_youtube.cr Show resolved Hide resolved
@@ -303,6 +303,7 @@ module Invidious::Comments
if format == "html"
response = JSON.parse(response)
content_html = Frontend::Comments.template_youtube(response, locale, thin_mode)
content_html = Comments.replace_external_links(content_html)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you added this here? Is it because you missed one link to replace, as mentioned here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for replacing the links on comments with the confirmation page, such as when creators pin their own with links from Discord or Twitch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay, I see!

@SamantazFox
Copy link
Member

Also, I realized that there was #4667 pending. I merged, so can you rebase your change on that please?

@unlxam unlxam force-pushed the confirm-leave branch 2 times, most recently from 28b8149 to 33b30c9 Compare August 24, 2024 14:39
@unlxam
Copy link
Author

unlxam commented Aug 25, 2024

Also, I realized that there was #4667 pending. I merged, so can you rebase your change on that please?

Rebased, since this PR goes directly with the feature of the confirmation page, I added the rel="noreferrer noopener" to it too, and replaced the external youtube.com links change by #4667 to pass through the confirmation.
Edit: I forgot to mention that I added the function to replace the links to the channel about/description too.

Comment on lines +51 to +57
if env.params.query["link"]? && !env.params.query["link"].empty?
link = HTML.escape(env.params.query["link"].to_s)

templated "confirm_leave"
else
env.redirect "#{referer}"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small improvements:

  • .presence will return nil if env.params.query["link"]? is either nil (= the parameter is absent) or an empty string. Otherwise, it returns its value.
  • you can assign a variable inside an if condition. The if will check if that variable is truthy or falsey.
  • For the referer, the string interpolation is superfluous
  • There was a trailing whitespace on the empty line after link = .... Don't forget to run make format to ensure that your code is properly formatted!
Suggested change
if env.params.query["link"]? && !env.params.query["link"].empty?
link = HTML.escape(env.params.query["link"].to_s)
templated "confirm_leave"
else
env.redirect "#{referer}"
end
if raw_link = env.params.query["link"]?.presence
link = HTML.escape(raw_link)
templated "confirm_leave"
else
env.redirect referer
end

<% end %>

<div class="h-box">
<h3><%= translate(locale, "You are leaving Invidious. Continue to external link?") %></h3>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the suggestion I made above! You need to use confirm_dialog_external_link, not the translated string here!

@@ -303,6 +303,7 @@ module Invidious::Comments
if format == "html"
response = JSON.parse(response)
content_html = Frontend::Comments.template_youtube(response, locale, thin_mode)
content_html = Comments.replace_external_links(content_html)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay, I see!

@SamantazFox SamantazFox added the unfinished More work is needed on this PR, or on something this PR uses. label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unfinished More work is needed on this PR, or on something this PR uses.
Projects
None yet
2 participants