Invidious is an alternative front-end to YouTube
Add 'comments' as URL parameter
Omar Rothefd54b752337
diff --git a/assets/js/watch.js b/assets/js/watch.jsindex 9b843920..c9cac43b 100644--- a/assets/js/watch.js+++ b/assets/js/watch.js@@ -237,7 +237,7 @@ function get_reddit_comments(timeouts = 0) {comments.children[0].children[0].children[0].onclick = toggle_comments;comments.children[0].children[1].children[0].onclick = swap_comments;} else {- if (video_data.preferences.comments[1] === 'youtube') {+ if (video_data.params.comments[1] === 'youtube') {get_youtube_comments(timeouts + 1);} else {comments.innerHTML = fallback;@@ -278,35 +278,31 @@ function get_youtube_comments(timeouts = 0) {xhr.onreadystatechange = function () {if (xhr.readyState == 4) {if (xhr.status == 200) {- if (xhr.response.commentCount > 0) {- comments.innerHTML = ' \- <div> \- <h3> \- <a href="javascript:void(0)">[ - ]</a> \- {commentsText} \- </h3> \- <b> \- <a href="javascript:void(0)" data-comments="reddit"> \- {redditComments} \- </a> \- </b> \- </div> \- <div>{contentHtml}</div> \- <hr>'.supplant({- contentHtml: xhr.response.contentHtml,- redditComments: video_data.reddit_comments_text,- commentsText: video_data.comments_text.supplant(- { commentCount: number_with_separator(xhr.response.commentCount) }- )- });+ comments.innerHTML = ' \+ <div> \+ <h3> \+ <a href="javascript:void(0)">[ - ]</a> \+ {commentsText} \+ </h3> \+ <b> \+ <a href="javascript:void(0)" data-comments="reddit"> \+ {redditComments} \+ </a> \+ </b> \+ </div> \+ <div>{contentHtml}</div> \+ <hr>'.supplant({+ contentHtml: xhr.response.contentHtml,+ redditComments: video_data.reddit_comments_text,+ commentsText: video_data.comments_text.supplant(+ { commentCount: number_with_separator(xhr.response.commentCount) }+ )+ });- comments.children[0].children[0].children[0].onclick = toggle_comments;- comments.children[0].children[1].children[0].onclick = swap_comments;- } else {- comments.innerHTML = '';- }+ comments.children[0].children[0].children[0].onclick = toggle_comments;+ comments.children[0].children[1].children[0].onclick = swap_comments;} else {- if (video_data.preferences[1] === 'youtube') {+ if (video_data.params.comments[1] === 'youtube') {get_youtube_comments(timeouts + 1);} else {comments.innerHTML = '';@@ -409,13 +405,13 @@ if (video_data.plid) {get_playlist(video_data.plid);}-if (video_data.preferences.comments[0] === 'youtube') {+if (video_data.params.comments[0] === 'youtube') {get_youtube_comments();-} else if (video_data.preferences.comments[0] === 'reddit') {+} else if (video_data.params.comments[0] === 'reddit') {get_reddit_comments();-} else if (video_data.preferences.comments[1] === 'youtube') {+} else if (video_data.params.comments[1] === 'youtube') {get_youtube_comments();-} else if (video_data.preferences.comments[1] === 'reddit') {+} else if (video_data.params.comments[1] === 'reddit') {get_reddit_comments();} else {comments = document.getElementById('comments');diff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex f5958017..8c059504 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -245,6 +245,7 @@ struct VideoPreferencesjson_mapping({annotations: Bool,autoplay: Bool,+ comments: Array(String),continue: Bool,continue_autoplay: Bool,controls: Bool,@@ -1228,6 +1229,7 @@ enddef process_video_params(query, preferences)annotations = query["iv_load_policy"]?.try &.to_i?autoplay = query["autoplay"]?.try &.to_i?+ comments = query["comments"]?.try &.split(",").map { |a| a.downcase }continue = query["continue"]?.try &.to_i?continue_autoplay = query["continue_autoplay"]?.try &.to_i?listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe@@ -1244,6 +1246,7 @@ def process_video_params(query, preferences)# region ||= preferences.regionannotations ||= preferences.annotations.to_unsafeautoplay ||= preferences.autoplay.to_unsafe+ comments ||= preferences.commentscontinue ||= preferences.continue.to_unsafecontinue_autoplay ||= preferences.continue_autoplay.to_unsafelisten ||= preferences.listen.to_unsafe@@ -1258,6 +1261,7 @@ def process_video_params(query, preferences)annotations ||= CONFIG.default_user_preferences.annotations.to_unsafeautoplay ||= CONFIG.default_user_preferences.autoplay.to_unsafe+ comments ||= CONFIG.default_user_preferences.commentscontinue ||= CONFIG.default_user_preferences.continue.to_unsafecontinue_autoplay ||= CONFIG.default_user_preferences.continue_autoplay.to_unsafelisten ||= CONFIG.default_user_preferences.listen.to_unsafe@@ -1306,6 +1310,7 @@ def process_video_params(query, preferences)params = VideoPreferences.new(annotations: annotations,autoplay: autoplay,+ comments: comments,continue: continue,continue_autoplay: continue_autoplay,controls: controls,