From 57d88ffcc8e68aa3f057a37b94bbe5cef6c895cf Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 15 Oct 2018 11:15:23 -0500 Subject: [PATCH] Fix fallback for comments --- assets/js/watch.js | 21 +++++++++++++----- src/invidious/views/watch.ecr | 42 +++++++++++++---------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/assets/js/watch.js b/assets/js/watch.js index 7301f075..4a84769e 100644 --- a/assets/js/watch.js +++ b/assets/js/watch.js @@ -21,11 +21,6 @@ function toggle_comments(target) { } function swap_comments(source) { - comments = document.getElementById("comments"); - var fallback = comments.innerHTML; - comments.innerHTML = - '

'; - if (source == "youtube") { get_youtube_comments(); } else if (source == "reddit") { @@ -46,3 +41,19 @@ String.prototype.supplant = function(o) { return typeof r === "string" || typeof r === "number" ? r : a; }); }; + +function show_youtube_replies(target) { + body = target.parentNode.parentNode.children[1]; + body.style.display = ""; + + target.innerHTML = "Hide replies"; + target.setAttribute("onclick", "hide_youtube_replies(this)"); +} + +function hide_youtube_replies(target) { + body = target.parentNode.parentNode.children[1]; + body.style.display = "none"; + + target.innerHTML = "Show replies"; + target.setAttribute("onclick", "show_youtube_replies(this)"); +} diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 5a86c219..456526f4 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -121,15 +121,12 @@
-

<% if plid %>
-

-
<% end %> @@ -200,6 +197,11 @@ function unsubscribe() { <% if plid %> function get_playlist() { + playlist = document.getElementById("playlist"); + playlist.innerHTML = ' \ +

\ +
' + var plid = "<%= plid %>" if (plid.startsWith("RD")) { @@ -217,7 +219,6 @@ function get_playlist() { xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { - playlist = document.getElementById("playlist"); playlist.innerHTML = xhr.response.playlistHtml; if (xhr.response.nextVideo) { @@ -257,6 +258,11 @@ get_playlist(); <% end %> function get_reddit_comments() { + comments = document.getElementById("comments"); + var fallback = comments.innerHTML; + comments.innerHTML = + '

'; + var url = "/api/v1/comments/<%= video.id %>?source=reddit&format=html"; var xhr = new XMLHttpRequest(); xhr.responseType = "json"; @@ -267,7 +273,6 @@ function get_reddit_comments() { xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { - comments = document.getElementById("comments"); comments.innerHTML = ' \
\

\ @@ -295,8 +300,7 @@ function get_reddit_comments() { <% if preferences && preferences.comments[1] == "youtube" %> get_youtube_comments(); <% else %> - comments = document.getElementById("comments"); - comments.innerHTML = ""; + comments.innerHTML = fallback; <% end %> } } @@ -310,6 +314,11 @@ function get_reddit_comments() { } function get_youtube_comments() { + comments = document.getElementById("comments"); + var fallback = comments.innerHTML; + comments.innerHTML = + '

'; + var url = "/api/v1/comments/<%= video.id %>?format=html"; var xhr = new XMLHttpRequest(); xhr.responseType = "json"; @@ -320,7 +329,6 @@ function get_youtube_comments() { xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { - comments = document.getElementById("comments"); if (xhr.response.commentCount > 0) { comments.innerHTML = ' \
\ @@ -346,7 +354,6 @@ function get_youtube_comments() { <% if preferences && preferences.comments[1] == "youtube" %> get_youtube_comments(); <% else %> - comments = document.getElementById("comments"); comments.innerHTML = ""; <% end %> } @@ -356,7 +363,6 @@ function get_youtube_comments() { xhr.ontimeout = function() { console.log("Pulling comments timed out."); - comments = document.getElementById("comments"); comments.innerHTML = '

'; get_youtube_comments(); @@ -402,22 +408,6 @@ function get_youtube_replies(target) { }; } -function show_youtube_replies(target) { - body = target.parentNode.parentNode.children[1]; - body.style.display = ""; - - target.innerHTML = "Hide replies"; - target.setAttribute('onclick', 'hide_youtube_replies(this)'); -} - -function hide_youtube_replies(target) { - body = target.parentNode.parentNode.children[1]; - body.style.display = "none"; - - target.innerHTML = "Show replies"; - target.setAttribute('onclick', 'show_youtube_replies(this)'); -} - <% if preferences %> <% if preferences.comments[0] == "youtube" %> get_youtube_comments();