Add btn to try reddit comments when yt is disabled

This commit is contained in:
syeopite 2023-08-08 22:41:47 -07:00
parent ab2e7a0600
commit 2e590ee67c
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
4 changed files with 46 additions and 2 deletions

View File

@ -72,7 +72,28 @@ 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.youtube_comments_disabled_text}</b></p>
<p>
<b>
<a href="javascript:void(0)" data-comments="reddit" id="try-reddit-comments-link">
${video_data.youtube_comments_disabled_try_reddit}
</a>
</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') {
@ -188,3 +192,5 @@ addEventListener('load', function (e) {
get_reddit_comments();
}
});
document.getElementById("try-reddit-comments-link").onclick = swap_comments

View File

@ -214,6 +214,7 @@
"Hide replies": "Hide replies",
"Show replies": "Show replies",
"youtube_comments_disabled_text": "Comments are turned off on this video",
"youtube_comments_disabled_try_reddit": "Try reddit comments?",
"invidious_comments_disabled_text": "Comments are hidden as per configuration",
"Incorrect password": "Incorrect password",
"Wrong answer": "Wrong answer",

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")),
"youtube_comments_disabled_text" => HTML.escape(translate(locale, "youtube_comments_disabled_text")),
"youtube_comments_disabled_try_reddit" => HTML.escape(translate(locale, "youtube_comments_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")),
@ -307,7 +315,15 @@ we're going to need to do it here in order to allow for translations.
<% end %>
<% else %>
<div id="comments-turned-off-on-video-message" class="h-box v-box">
<p><b><%=translate(locale, "youtube_comments_disabled_text")%></b></p>
<p><b><%=translate(locale, "youtube_comments_disabled_text")%></b></p>
<p>
<b>
<a href="javascript:void(0)" data-comments="reddit" id="try-reddit-comments-link">
<%=HTML.escape(translate(locale, "youtube_comments_disabled_try_reddit"))%>
</a>
</b>
</p>
</div>
<% end %>
<% end %>