mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-14 17:15:09 +00:00
Merge 'Show message when comments are turned off'
From https://github.com/iv-org/invidious/pull/4051
This commit is contained in:
@@ -84,7 +84,8 @@ module Invidious::Routes::Watch
|
||||
|
||||
if nojs
|
||||
if preferences
|
||||
source = preferences.comments[0]
|
||||
source = video.comments? ? preferences.comments[0] : "reddit"
|
||||
|
||||
if source.empty?
|
||||
source = preferences.comments[1]
|
||||
end
|
||||
|
||||
@@ -196,6 +196,11 @@ struct Video
|
||||
info["invidiousCompanion"]?.try &.as_h || {} of String => JSON::Any
|
||||
end
|
||||
|
||||
# Returns true if comments are enabled on the video
|
||||
def comments?
|
||||
return info["commentsEnabled"].as_bool
|
||||
end
|
||||
|
||||
# Macros defining getters/setters for various types of data
|
||||
|
||||
private macro getset_string(name)
|
||||
|
||||
@@ -407,6 +407,18 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
||||
.try &.as_s.split(" ", 2)[0]
|
||||
end
|
||||
|
||||
# Comments enabled?
|
||||
comments_enabled = false
|
||||
|
||||
# When comments are enabled there should be a comments-entry-point section in the primary results
|
||||
if primary_results
|
||||
section = primary_results.as_a.find(&.dig?("itemSectionRenderer", "sectionIdentifier").== "comments-entry-point")
|
||||
|
||||
if section
|
||||
comments_enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
# Return data
|
||||
|
||||
if live_now
|
||||
@@ -432,6 +444,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
||||
"isFamilyFriendly" => JSON::Any.new(family_friendly || false),
|
||||
"isListed" => JSON::Any.new(is_listed || false),
|
||||
"isUpcoming" => JSON::Any.new(is_upcoming || false),
|
||||
"commentsEnabled" => JSON::Any.new(comments_enabled),
|
||||
"keywords" => JSON::Any.new(keywords.map { |v| JSON::Any.new(v) }),
|
||||
"isPostLiveDvr" => JSON::Any.new(post_live_dvr),
|
||||
# Related videos
|
||||
|
||||
@@ -46,6 +46,12 @@ we're going to need to do it here in order to allow for translations.
|
||||
content: "<%= translate(locale, "Show less") %>"
|
||||
}
|
||||
</style>
|
||||
|
||||
<%
|
||||
# Disable the try reddit link if javascript is disabled
|
||||
%>
|
||||
<noscript><style> #try-reddit-comments-link { display: none } </style></noscript>
|
||||
|
||||
<% end %>
|
||||
|
||||
<script id="video_data" type="application/json">
|
||||
@@ -60,6 +66,8 @@ we're going to need to do it here in order to allow for translations.
|
||||
"youtube_comments_text" => HTML.escape(translate(locale, "View YouTube comments")),
|
||||
"reddit_comments_text" => HTML.escape(translate(locale, "View Reddit comments")),
|
||||
"reddit_permalink_text" => HTML.escape(translate(locale, "View more comments on Reddit")),
|
||||
"comments_youtube_disabled_text" => HTML.escape(translate(locale, "comments_youtube_disabled_text")),
|
||||
"comments_youtube_disabled_try_reddit" => HTML.escape(translate(locale, "comments_youtube_disabled_try_reddit")),
|
||||
"comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")),
|
||||
"hide_replies_text" => HTML.escape(translate(locale, "Hide replies")),
|
||||
"show_replies_text" => HTML.escape(translate(locale, "Show replies")),
|
||||
@@ -67,6 +75,7 @@ we're going to need to do it here in order to allow for translations.
|
||||
"preferences" => preferences,
|
||||
"premiere_timestamp" => video.premiere_timestamp.try &.to_unix,
|
||||
"vr" => video.vr?,
|
||||
"comments_enabled" => video.comments?,
|
||||
"projection_type" => video.projection_type,
|
||||
"local_disabled" => CONFIG.disabled?("local"),
|
||||
"support_reddit" => true
|
||||
@@ -310,14 +319,41 @@ we're going to need to do it here in order to allow for translations.
|
||||
|
||||
<% end %>
|
||||
<div id="comments" class="comments">
|
||||
<% if nojs %>
|
||||
<%= comment_html %>
|
||||
<% if (params.comments <=> ["", ""]) == 0 %>
|
||||
<div id="comments-disabled-message" class="h-box v-box">
|
||||
<p><b><%=HTML.escape(translate(locale, "comments_invidious_disabled_text"))%></b></p>
|
||||
</div>
|
||||
<% else %>
|
||||
<noscript>
|
||||
<a href="/watch?<%= env.params.query %>&nojs=1">
|
||||
<%= translate(locale, "Hi! Looks like you have JavaScript turned off. Click here to view comments, keep in mind they may take a bit longer to load.") %>
|
||||
</a>
|
||||
</noscript>
|
||||
<% if video.comments? %>
|
||||
<% if nojs %>
|
||||
<%= comment_html %>
|
||||
<% else %>
|
||||
<noscript>
|
||||
<a href="/watch?<%= env.params.query %>&nojs=1">
|
||||
<%= translate(locale, "Hi! Looks like you have JavaScript turned off. Click here to view comments, keep in mind they may take a bit longer to load.") %>
|
||||
</a>
|
||||
</noscript>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% if !nojs %>
|
||||
<div id="comments-turned-off-on-video-message" class="h-box v-box">
|
||||
<p><b><%=HTML.escape(translate(locale, "comments_youtube_disabled_text"))%></b></p>
|
||||
<p><b><button data-comments="reddit" id="try-reddit-comments-link" class="simulated_a">
|
||||
<%=HTML.escape(translate(locale, "comments_youtube_disabled_try_reddit"))%>
|
||||
</button></b></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<noscript>
|
||||
<% if nojs %>
|
||||
<%= comment_html %>
|
||||
<% else %>
|
||||
<a href="/watch?<%= env.params.query %>&nojs=1">
|
||||
<%= translate(locale, "comments_youtube_disabled_try_reddit_no_js") %>
|
||||
</a>
|
||||
<% end %>
|
||||
</noscript>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user