Show message when comments are turned off (#4051)

* Add error message when comments are disabled

* Add btn to try reddit comments when yt is disabled

* Escape warning messages for disabled comments

* Add missing semicolons

* Update comment detection to not use msg renderer

* Use short syntax for comment entry-point detection

Co-authored-by: Samantaz Fox <coding@samantaz.fr>

* Condense try-reddit-comments-link HTML in player.js

Co-authored-by: Samantaz Fox <coding@samantaz.fr>

* Improve locale keys for comments disabled messages

Co-authored-by: Samantaz Fox <coding@samantaz.fr>

* Remove extra whitespace

* Use button instead of anchor for try reddit link

* Request Reddit comm when yt disabled during nojs=1

* Change order of commentsEnabled in parse results

* Lint

* Rebase error

* update the naming of the comments section in Innertube

Downstreamed from 36ac67610d

---------

Co-authored-by: Samantaz Fox <coding@samantaz.fr>
Co-authored-by: Fijxu <fijxu@nadeko.net>
This commit is contained in:
syeopite
2026-08-03 19:18:13 +00:00
committed by GitHub
parent 986471320d
commit 4501c9df9c
8 changed files with 118 additions and 22 deletions

View File

@@ -79,7 +79,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

View File

@@ -193,6 +193,11 @@ struct Video
}
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)

View File

@@ -295,6 +295,18 @@ module Invidious::Videos::Parser
"likeButton", "toggleButtonRenderer"
)
# Comments enabled?
comments_enabled = false
# When comments are enabled there should be a comments-section section in the primary results
if primary_results
section = primary_results.as_a.find(&.dig?("itemSectionRenderer", "targetId").== "comments-section")
if section
comments_enabled = true
end
end
if likes_button
likes_txt = likes_button.dig?("accessibilityText")
# Note: The like count from `toggledText` is off by one, as it would
@@ -421,6 +433,7 @@ module Invidious::Videos::Parser
"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

View File

@@ -42,6 +42,12 @@ we're going to need to do it here in order to allow for translations.
content: "<%= I18n.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">
@@ -54,6 +60,8 @@ we're going to need to do it here in order to allow for translations.
"play_next" => !video.related_videos.empty? && !plid && params.continue,
"next_video" => video.related_videos.select { |rv| rv["id"]? }[0]?.try &.["id"],
"youtube_comments_text" => HTML.escape(I18n.translate(locale, "View YouTube comments")),
"comments_youtube_disabled_text" => HTML.escape(I18n.translate(locale, "comments_youtube_disabled_text")),
"comments_youtube_disabled_try_reddit" => HTML.escape(I18n.translate(locale, "comments_youtube_disabled_try_reddit")),
"reddit_comments_text" => HTML.escape(I18n.translate(locale, "View Reddit comments")),
"reddit_permalink_text" => HTML.escape(I18n.translate(locale, "View more comments on Reddit")),
"comments_text" => HTML.escape(I18n.translate(locale, "View `x` comments", "{commentCount}")),
@@ -63,6 +71,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,
@@ -289,14 +298,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(I18n.translate(locale, "comments_invidious_disabled_text")) %></b></p>
</div>
<% else %>
<noscript>
<a href="/watch?<%= env.params.query %>&nojs=1">
<%= I18n.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">
<%= I18n.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(I18n.translate(locale, "comments_youtube_disabled_text")) %></b></p>
<p><b><button data-comments="reddit" id="try-reddit-comments-link" class="simulated_a">
<%= HTML.escape(I18n.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">
<%= I18n.translate(locale, "comments_youtube_disabled_try_reddit_no_js") %>
</a>
<% end %>
</noscript>
<% end %>
<% end %>
</div>
</div>