diff --git a/assets/js/comments.js b/assets/js/comments.js index b5aae6771..3200423a4 100644 --- a/assets/js/comments.js +++ b/assets/js/comments.js @@ -3,10 +3,12 @@ var video_data = JSON.parse(document.getElementById('video_data').textContent); var spinnerHTML = '

'; var spinnerHTMLwithHR = spinnerHTML + '
'; -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 diff --git a/locales/en-US.json b/locales/en-US.json index 08eda15ab..358af3dd2 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -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" } diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 069d6948f..9676c26ac 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -305,10 +305,10 @@ we're going to need to do it here in order to allow for translations. <% end %>
@@ -323,16 +323,16 @@ we're going to need to do it here in order to allow for translations.
<% env.params.query.each do |key, value| %> <% if key != "sort_by" && key != "nojs" %> - + <% end %> <% end %> - - + + - +
<%= comment_html %> @@ -342,16 +342,16 @@ we're going to need to do it here in order to allow for translations.
<% env.params.query.each do |key, value| %> <% if key != "sort_by" && key != "nojs" %> - + <% end %> <% end %> - - + + - +
<% end %>