Compare commits

...

16 Commits

Author SHA1 Message Date
syeopite
b8fd37a78d
Merge bfbfec2b16 into bad92093bf 2024-07-10 19:24:39 -07:00
syeopite
bfbfec2b16
Rebase error 2024-01-05 12:22:00 -08:00
syeopite
8427074964
Lint 2024-01-05 12:22:00 -08:00
syeopite
249886ea42
Change order of commentsEnabled in parse results 2024-01-05 12:21:59 -08:00
syeopite
9311724e69
Request Reddit comm when yt disabled during nojs=1 2024-01-05 12:21:59 -08:00
syeopite
41f82f189b
Use button instead of anchor for try reddit link 2024-01-05 12:21:59 -08:00
syeopite
3601d42716
Remove extra whitespace 2024-01-05 12:21:59 -08:00
syeopite
9665b82fb5
Improve locale keys for comments disabled messages
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
2024-01-05 12:21:59 -08:00
syeopite
7caa9da988
Condense try-reddit-comments-link HTML in player.js
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
2024-01-05 12:21:59 -08:00
syeopite
a455df4a6e
Use short syntax for comment entry-point detection
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
2024-01-05 12:21:59 -08:00
syeopite
83953d7fc2
Update comment detection to not use msg renderer 2024-01-05 12:21:59 -08:00
syeopite
b95d5604f8
Bump Video struct schema version 2024-01-05 12:21:59 -08:00
syeopite
561ce9e949
Add missing semicolons 2024-01-05 12:21:59 -08:00
syeopite
38063bbd23
Escape warning messages for disabled comments 2024-01-05 12:21:59 -08:00
syeopite
2e590ee67c
Add btn to try reddit comments when yt is disabled 2024-01-05 12:21:59 -08:00
syeopite
ab2e7a0600
Add error message when comments are disabled 2024-01-05 12:21:38 -08:00
8 changed files with 117 additions and 21 deletions

View File

@ -58,6 +58,11 @@ body {
justify-content: flex-end;
}
button.simulated_a {
background: none;
border: none;
}
/*
* Channel page
@ -499,7 +504,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;
}
@ -517,7 +524,7 @@ span > select {
background-color: #fff2;
}
.light-theme a {
.light-theme a, .light-theme .simulated_a {
color: #335d7a;
text-decoration: none;
}
@ -538,7 +545,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;
}
@ -556,7 +565,7 @@ span > select {
background-color: #fff2;
}
.no-theme a {
.no-theme a, .no-theme .simulated_a{
color: #335d7a;
text-decoration: none;
}
@ -590,7 +599,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);
}
@ -608,7 +619,7 @@ span > select {
color: #ddd;
}
.dark-theme a {
.dark-theme a, .dark-theme .simulated_a {
color: #adadad;
text-decoration: none;
}
@ -644,7 +655,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);
}
@ -662,7 +675,7 @@ body.dark-theme {
color: #ddd;
}
.no-theme a {
.no-theme a, .no-theme .simulated_a{
color: #adadad;
text-decoration: none;
}
@ -799,3 +812,7 @@ h1, h2, h3, h4, h5, p,
#download_widget {
width: 100%;
}
#comments-turned-off-on-video-message > p, #comments-disabled-message > p {
text-align: center;
}

View File

@ -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 = `
<div id="comments-turned-off-on-video-message" class="h-box v-box">
<p><b>${video_data.comments_youtube_disabled_text}</b></p>
<p><b><button href="javascript:void(0)" data-comments="reddit" id="try-reddit-comments-link" class="simulated_a">
${video_data.comments_youtube_disabled_try_reddit}
</button></b></p>
</div>`;
document.getElementById("try-reddit-comments-link").onclick = swap_comments;
} else {
comments.innerHTML = fallback;
}
};
if (video_data.params.comments[1] === 'youtube')
onNon200 = function (xhr) {};

View File

@ -178,6 +178,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') {
@ -186,8 +190,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;

View File

@ -218,6 +218,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",

View File

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

@ -15,7 +15,7 @@ struct Video
# NOTE: don't forget to bump this number if any change is made to
# the `params` structure in videos/parser.cr!!!
#
SCHEMA_VERSION = 2
SCHEMA_VERSION = 3
property id : String
@ -276,6 +276,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

@ -389,6 +389,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
@ -414,6 +426,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

View File

@ -42,6 +42,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">
@ -56,6 +62,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")),
@ -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.is_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(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>