From 0fd38e52efc17191ffc2a8605e148050cdf064d6 Mon Sep 17 00:00:00 2001 From: unlxam <177877261+unlxam@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:01:37 -0300 Subject: [PATCH] refactor: replace all youtube external links with confirmation page --- src/invidious/frontend/comments_youtube.cr | 4 +++- src/invidious/helpers/errors.cr | 5 ++++- src/invidious/views/components/video-context-buttons.ecr | 6 +++++- src/invidious/views/playlist.ecr | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index 93edffdc..5e9faece 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -157,8 +157,10 @@ module Invidious::Frontend::Comments | END_HTML elsif comments["authorId"]? + permalink = "https://www.youtube.com/channel/#{comments["authorId"]}/community?lb=#{child["commentId"]}" + permalink_confirm = "/confirm_leave?link=#{URI.encode_path(permalink)}" html << <<-END_HTML - [YT] + [YT] | END_HTML end diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index b2df682d..c8e360dc 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -180,6 +180,9 @@ def error_redirect_helper(env : HTTP::Server::Context) go_to_youtube = translate(locale, "next_steps_error_message_go_to_youtube") switch_instance = translate(locale, "Switch Invidious Instance") + youtube_link = "https://youtube.com#{env.request.resource}" + youtube_link_confirm = "/confirm_leave?link=#{URI.encode_path(youtube_link)}" + return <<-END_HTML

#{next_steps_text}

END_HTML diff --git a/src/invidious/views/components/video-context-buttons.ecr b/src/invidious/views/components/video-context-buttons.ecr index 22458a03..a8078da8 100644 --- a/src/invidious/views/components/video-context-buttons.ecr +++ b/src/invidious/views/components/video-context-buttons.ecr @@ -1,6 +1,10 @@
- " rel="noreferrer noopener" href="https://www.youtube.com/watch<%=endpoint_params%>"> + <%- + watch_yt = "https://www.youtube.com/watch#{endpoint_params}" + confirm_watch_yt = "/confirm_leave?link=#{URI.encode_path(watch_yt)}" + -%> + " href="<%= confirm_watch_yt %>"> " href="/watch<%=endpoint_params%>&listen=1"> diff --git a/src/invidious/views/playlist.ecr b/src/invidious/views/playlist.ecr index c27ddba6..031a03ae 100644 --- a/src/invidious/views/playlist.ecr +++ b/src/invidious/views/playlist.ecr @@ -83,7 +83,11 @@ <% if !playlist.is_a? InvidiousPlaylist %>