diff --git a/assets/css/default.css b/assets/css/default.css
index 749e372d..96c4198a 100644
--- a/assets/css/default.css
+++ b/assets/css/default.css
@@ -58,6 +58,11 @@ body {
justify-content: flex-end;
}
+button.simulated_a {
+ background: none;
+ border: none;
+}
+
/*
* Channel page
@@ -554,7 +559,9 @@ span > select {
.light-theme a:active,
.light-theme summary:hover,
.light-theme a:focus,
-.light-theme summary:focus {
+.light-theme summary:focus,
+.light-theme .simulated_a:hover,
+.light-theme .simulated_a:active {
color: #075A9E !important;
}
@@ -572,7 +579,7 @@ span > select {
background-color: #fff2;
}
-.light-theme a {
+.light-theme a, .light-theme .simulated_a {
color: #335d7a;
text-decoration: none;
}
@@ -614,7 +621,9 @@ span > select {
.no-theme a:active,
.no-theme summary:hover,
.no-theme a:focus,
- .no-theme summary:focus {
+ .no-theme summary:focus,
+ .no-theme .simulated_a:hover,
+ .no-theme .simulated_a:active {
color: #075A9E !important;
}
@@ -632,7 +641,7 @@ span > select {
background-color: #fff2;
}
- .no-theme a {
+ .no-theme a, .no-theme .simulated_a{
color: #335d7a;
text-decoration: none;
}
@@ -679,7 +688,9 @@ span > select {
.dark-theme a:active,
.dark-theme summary:hover,
.dark-theme a:focus,
-.dark-theme summary:focus {
+.dark-theme summary:focus,
+.dark-theme .simulated_a:hover,
+.dark-theme .simulated_a:active {
color: rgb(0, 182, 240);
}
@@ -697,7 +708,7 @@ span > select {
color: #ddd;
}
-.dark-theme a {
+.dark-theme a, .dark-theme .simulated_a {
color: #adadad;
text-decoration: none;
}
@@ -751,7 +762,9 @@ body.dark-theme {
@media (prefers-color-scheme: dark) {
.no-theme a:hover,
.no-theme a:active,
- .no-theme a:focus {
+ .no-theme a:focus,
+ .no-theme .simulated_a:hover,
+ .no-theme .simulated_a:active {
color: rgb(0, 182, 240);
}
@@ -769,7 +782,7 @@ body.dark-theme {
color: #ddd;
}
- .no-theme a {
+ .no-theme a, .no-theme .simulated_a{
color: #adadad;
text-decoration: none;
}
@@ -975,4 +988,8 @@ h1, h2, h3, h4, h5, p,
.error-issue-template {
padding: 20px;
background: rgba(0, 0, 0, 0.12345);
-}
\ No newline at end of file
+}
+
+#comments-turned-off-on-video-message > p, #comments-disabled-message > p {
+ text-align: center;
+}
diff --git a/assets/js/comments.js b/assets/js/comments.js
index 35ffa96e..ac519388 100644
--- a/assets/js/comments.js
+++ b/assets/js/comments.js
@@ -68,7 +68,24 @@ function get_youtube_comments() {
url += '&ucid=' + video_data.ucid
}
- var onNon200 = function (xhr) { comments.innerHTML = fallback; };
+ var onNon200 = function (xhr) {
+ if (!video_data.comments_enabled) {
+ comments.innerHTML = `
+
`;
+
+ document.getElementById("try-reddit-comments-link").onclick = swap_comments;
+ } else {
+ comments.innerHTML = fallback;
+ }
+
+ };
+
if (video_data.params.comments[1] === 'youtube')
onNon200 = function (xhr) {};
diff --git a/assets/js/watch.js b/assets/js/watch.js
index d869d40d..26016913 100644
--- a/assets/js/watch.js
+++ b/assets/js/watch.js
@@ -182,6 +182,10 @@ addEventListener('load', function (e) {
if (video_data.plid)
get_playlist(video_data.plid);
+ if (!video_data.comments_enabled && video_data.params.comments.includes("youtube")) {
+ return;
+ }
+
if (video_data.params.comments[0] === 'youtube') {
get_youtube_comments();
} else if (video_data.params.comments[0] === 'reddit') {
@@ -190,8 +194,7 @@ addEventListener('load', function (e) {
get_youtube_comments();
} else if (video_data.params.comments[1] === 'reddit') {
get_reddit_comments();
- } else {
- var comments = document.getElementById('comments');
- comments.innerHTML = '';
}
});
+
+document.getElementById("try-reddit-comments-link").onclick = swap_comments;
diff --git a/locales/en-US.json b/locales/en-US.json
index ad3f6ffd..07a458e6 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -221,6 +221,10 @@
"View Reddit comments": "View Reddit comments",
"Hide replies": "Hide replies",
"Show replies": "Show replies",
+ "comments_youtube_disabled_text": "Youtube comments are disabled on this video",
+ "comments_youtube_disabled_try_reddit": "Try reddit comments?",
+ "comments_invidious_disabled_text": "Comments are hidden as per user preferences",
+ "comments_youtube_disabled_try_reddit_no_js": "Hi! Looks like you have JavaScript turned off. Although the uploader has disabled YouTube comments you can still click here to try and view Reddit comments, keep in mind they may take a bit longer to load.",
"Incorrect password": "Incorrect password",
"Wrong answer": "Wrong answer",
"Erroneous CAPTCHA": "Erroneous CAPTCHA",
diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr
index bd1b9481..151fe569 100644
--- a/src/invidious/routes/watch.cr
+++ b/src/invidious/routes/watch.cr
@@ -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
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index e288b152..10c66090 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -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)
diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index 6f9bc565..f13a3bb5 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -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
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 79953121..43c6744c 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -46,6 +46,12 @@ we're going to need to do it here in order to allow for translations.
content: "<%= translate(locale, "Show less") %>"
}
+
+<%
+ # Disable the try reddit link if javascript is disabled
+%>
+
+
<% end %>
${video_data.comments_youtube_disabled_text}
+ ++