Fixed some issues

This commit is contained in:
RadoslavL 2026-09-26 19:39:09 +03:00
parent 7e67e10666
commit cba0f21021
3 changed files with 33 additions and 22 deletions

View File

@ -3,10 +3,12 @@ var video_data = JSON.parse(document.getElementById('video_data').textContent);
var spinnerHTML = '<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
var spinnerHTMLwithHR = spinnerHTML + '<hr>';
document.getElementById('sort-type-div').style.display = "block";
document.getElementById('sort_by').addEventListener('change', function(){
get_youtube_comments();
});
sort_by_div = document.getElementById('sort-type-div');
sort_by_select = document.getElementById('sort_by');
if (sort_by_div && sort_by_select){
sort_by_div.style.display = "block";
sort_by_select.addEventListener('change', get_youtube_comments);
}
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g, function (a, b) {
@ -63,14 +65,19 @@ function get_youtube_comments() {
var fallback = comments.innerHTML;
comments.innerHTML = spinnerHTML;
var sort_by = document.getElementById('sort_by').value;
var sort_by = document.getElementById('sort_by');
if(sort_by){
sort_by_value = sort_by.value;
}else{
sort_by_value = "top";
}
var baseUrl = video_data.base_url || '/api/v1/comments/'+ video_data.id
var url = baseUrl +
'?format=html' +
'&hl=' + video_data.preferences.locale +
'&thin_mode=' + video_data.preferences.thin_mode +
'&sort_by=' + sort_by;
'&sort_by=' + sort_by_value;
if (video_data.ucid) {
url += '&ucid=' + video_data.ucid

View File

@ -513,5 +513,9 @@
"timeline_parse_error_placeholder_message": "Invidious encountered an error while trying to parse this item. For more information see below:",
"timeline_parse_error_show_technical_details": "Show technical details",
"dmca_content": "This video cannot be downloaded on this instance due to a DMCA/copyright infringement letter sent to the instance administrator.",
"Hi! Looks like you have JavaScript turned off. Click the \"Fetch comments\" button below to view comments, keep in mind they may take a bit longer to load.": "Hi! Looks like you have JavaScript turned off. Click the \"Fetch comments\" button below to view comments, keep in mind they may take a bit longer to load."
"Hi! Looks like you have JavaScript turned off. Click the \"Fetch comments\" button below to view comments, keep in mind they may take a bit longer to load.": "Hi! Looks like you have JavaScript turned off. Click the \"Fetch comments\" button below to view comments, keep in mind they may take a bit longer to load.",
"comments_sort_label": "Sort comments by: ",
"comments_sort_top": "Top",
"comments_sort_new": "New",
"comments_sort_submitbtn": "Fetch comments"
}

View File

@ -305,10 +305,10 @@ we're going to need to do it here in order to allow for translations.
<% end %>
<div class="pure-form pure-form-aligned" id="sort-type-div" style="display: none">
<label for="sort_by">Sort comments by: </label>
<label for="sort_by"><%= I18n.translate(locale, "comments_sort_label") %></label>
<select name="sort_by" id="sort_by">
<option value="top">Top</option>
<option value="new">New</option>
<option value="top"><%= I18n.translate(locale, "comments_sort_top") %></option>
<option value="new"><%= I18n.translate(locale, "comments_sort_new") %></option>
</select>
</div>
<div id="comments" class="comments">
@ -323,16 +323,16 @@ we're going to need to do it here in order to allow for translations.
<form class="pure-form pure-form-aligned" action="/watch" method="get">
<% env.params.query.each do |key, value| %>
<% if key != "sort_by" && key != "nojs" %>
<input type="hidden" name="<%= key %>" value="<%= value %>">
<input type="hidden" name="<%= HTML.escape(key) %>" value="<%= HTML.escape(value) %>">
<% end %>
<% end %>
<input type="hidden" name="nojs" value="1">
<label for="sort_by">Sort comments by: </label>
<select name="sort_by" id="sort_by">
<option value="top" <% if sort_by == "top" %> selected <% end %> >Top</option>
<option value="new" <% if sort_by == "new" %> selected <% end %> >New</option>
<label for="sort_by"><%= I18n.translate(locale, "comments_sort_label") %></label>
<select name="sort_by" id="sort_by_nojs">
<option value="top" <% if sort_by == "top" %> selected <% end %> ><%= I18n.translate(locale, "comments_sort_top") %></option>
<option value="new" <% if sort_by == "new" %> selected <% end %> ><%= I18n.translate(locale, "comments_sort_new") %></option>
</select>
<button type="submit">Fetch comments</button>
<button type="submit"><%= I18n.translate(locale, "comments_sort_submitbtn") %></button>
</form>
<%= comment_html %>
</noscript>
@ -342,16 +342,16 @@ we're going to need to do it here in order to allow for translations.
<form class="pure-form pure-form-aligned" action="/watch" method="get">
<% env.params.query.each do |key, value| %>
<% if key != "sort_by" && key != "nojs" %>
<input type="hidden" name="<%= key %>" value="<%= value %>">
<input type="hidden" name="<%= HTML.escape(key) %>" value="<%= HTML.escape(value) %>">
<% end %>
<% end %>
<input type="hidden" name="nojs" value="1">
<label for="sort_by">Sort comments by: </label>
<select name="sort_by" id="sort_by">
<option value="top">Top</option>
<option value="new">New</option>
<label for="sort_by"><%= I18n.translate(locale, "comments_sort_label") %></label>
<select name="sort_by" id="sort_by_noscript">
<option value="top"><%= I18n.translate(locale, "comments_sort_top") %></option>
<option value="new"><%= I18n.translate(locale, "comments_sort_new") %></option>
</select>
<button type="submit">Fetch comments</button>
<button type="submit"><%= I18n.translate(locale, "comments_sort_submitbtn") %></button>
</form>
</noscript>
<% end %>