mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
Merge 811dad07c9
into 9bf754ed4f
This commit is contained in:
commit
a90adf7127
8 changed files with 73 additions and 3 deletions
|
@ -73,4 +73,30 @@ module Invidious::Comments
|
|||
|
||||
return html.to_xml(options: XML::SaveOptions::NO_DECL)
|
||||
end
|
||||
|
||||
def replace_external_links(html)
|
||||
# Check if the document is empty
|
||||
# Prevents edge-case bug with Reddit comments, see issue #3115
|
||||
if html.nil? || html.empty?
|
||||
return html
|
||||
end
|
||||
|
||||
html = XML.parse_html(html)
|
||||
|
||||
html.xpath_nodes(%q(//a)).each do |anchor|
|
||||
url = URI.parse(anchor["href"])
|
||||
|
||||
if !url.host.nil? && !url.host.not_nil!.ends_with?("youtube.com") && !url.host.not_nil!.ends_with?("youtu.be")
|
||||
confirm_leave = "/confirm_leave?link=#{URI.encode_path(url.to_s)}"
|
||||
anchor["href"] = confirm_leave
|
||||
end
|
||||
end
|
||||
|
||||
html = html.xpath_node(%q(//body)).not_nil!
|
||||
if node = html.xpath_node(%q(./p))
|
||||
html = node
|
||||
end
|
||||
|
||||
return html.to_xml(options: XML::SaveOptions::NO_DECL)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
response = JSON.build do |json|
|
||||
json.object do
|
||||
json.field "contentHtml", content_html
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "uri"
|
||||
|
||||
module Invidious::Frontend::Comments
|
||||
extend self
|
||||
|
||||
|
@ -148,8 +150,10 @@ module Invidious::Frontend::Comments
|
|||
END_HTML
|
||||
|
||||
if comments["videoId"]?
|
||||
permalink = "https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}"
|
||||
permalink_confirm = "/confirm_leave?link=#{URI.encode_path(permalink)}"
|
||||
html << <<-END_HTML
|
||||
<a href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
||||
<a href="#{permalink_confirm}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
||||
|
|
||||
END_HTML
|
||||
elsif comments["authorId"]?
|
||||
|
|
|
@ -43,4 +43,14 @@ module Invidious::Routes::Misc
|
|||
instance_url = fetch_random_instance
|
||||
env.redirect "https://#{instance_url}#{referer}"
|
||||
end
|
||||
|
||||
def self.confirm_leave(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
link = env.params.query["link"]?
|
||||
|
||||
referer = get_referer(env)
|
||||
|
||||
templated "confirm_leave"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ module Invidious::Routing
|
|||
get "/privacy", Routes::Misc, :privacy
|
||||
get "/licenses", Routes::Misc, :licenses
|
||||
get "/redirect", Routes::Misc, :cross_instance_redirect
|
||||
get "/confirm_leave", Routes::Misc, :confirm_leave
|
||||
|
||||
self.register_channel_routes
|
||||
self.register_watch_routes
|
||||
|
|
|
@ -311,6 +311,9 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||
|
||||
description_html = parse_description(video_secondary_renderer.try &.dig?("attributedDescription"), video_id)
|
||||
|
||||
# use comments link_utils to replace external links with the confirmation page
|
||||
description_html = Invidious::Comments.replace_external_links(description_html)
|
||||
|
||||
# Video metadata
|
||||
|
||||
metadata = video_secondary_renderer
|
||||
|
|
22
src/invidious/views/confirm_leave.ecr
Normal file
22
src/invidious/views/confirm_leave.ecr
Normal file
|
@ -0,0 +1,22 @@
|
|||
<% content_for "header" do %>
|
||||
<title><%= translate(locale, "Leave") %> - Invidious</title>
|
||||
<% end %>
|
||||
|
||||
<div class="h-box">
|
||||
<h3><%= translate(locale, "You are leaving Invidious. Continue to external link?") %></h3>
|
||||
|
||||
<p><%= link %></p>
|
||||
|
||||
<div class="pure-g">
|
||||
<div class="pure-u-1-2">
|
||||
<a value="confirm_leave" class="pure-button pure-button-primary" href="<%= link %>">
|
||||
<%= translate(locale, "Yes") %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pure-u-1-2">
|
||||
<a class="pure-button" href="<%= referer %>">
|
||||
<%= translate(locale, "No") %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -122,9 +122,12 @@ we're going to need to do it here in order to allow for translations.
|
|||
link_yt_watch = IV::HttpServer::Utils.add_params_to_url(link_yt_watch, link_yt_param)
|
||||
link_yt_embed = IV::HttpServer::Utils.add_params_to_url(link_yt_embed, link_yt_param)
|
||||
end
|
||||
|
||||
confirm_yt_watch = "/confirm_leave?link=#{URI.encode_path(link_yt_watch.to_s)}"
|
||||
confirm_yt_embed = "/confirm_leave?link=#{URI.encode_path(link_yt_embed.to_s)}"
|
||||
-%>
|
||||
<a id="link-yt-watch" data-base-url="<%= link_yt_watch %>" href="<%= link_yt_watch %>"><%= translate(locale, "videoinfo_watch_on_youTube") %></a>
|
||||
(<a id="link-yt-embed" data-base-url="<%= link_yt_embed %>" href="<%= link_yt_embed %>"><%= translate(locale, "videoinfo_youTube_embed_link") %></a>)
|
||||
<a id="link-yt-watch" data-base-url="<%= confirm_yt_watch %>" href="<%= confirm_yt_watch %>"><%= translate(locale, "videoinfo_watch_on_youTube") %></a>
|
||||
(<a id="link-yt-embed" data-base-url="<%= confirm_yt_embed %>" href="<%= confirm_yt_embed %>"><%= translate(locale, "videoinfo_youTube_embed_link") %></a>)
|
||||
</span>
|
||||
|
||||
<p id="watch-on-another-invidious-instance">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue