From 81ea2bf799742a2b93de3d75cc132c1290015e63 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 22 Oct 2018 17:15:36 -0500 Subject: [PATCH] Don't nest YouTube replies --- src/invidious/comments.cr | 2 +- src/invidious/views/watch.ecr | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 6a42701c..09eb4fed 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -129,7 +129,7 @@ def template_youtube_comments(comments)

Load more + onclick="get_youtube_replies(this, true)">Load more

diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 6af7e10a..83120fb2 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -379,7 +379,7 @@ function get_youtube_comments() { }; } -function get_youtube_replies(target) { +function get_youtube_replies(target, load_more) { var continuation = target.getAttribute('data-continuation'); var body = target.parentNode.parentNode; @@ -398,13 +398,19 @@ function get_youtube_replies(target) { xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { - body.innerHTML = ' \ -

Hide replies \ -

\ -
{contentHtml}
'.supplant({ - contentHtml: xhr.response.contentHtml, - }); + if (load_more) { + body = body.parentNode.parentNode; + body.removeChild(body.lastElementChild); + body.innerHTML += xhr.response.contentHtml; + } else { + body.innerHTML = ' \ +

Hide replies \ +

\ +
{contentHtml}
'.supplant({ + contentHtml: xhr.response.contentHtml, + }); + } } else { body.innerHTML = fallback; }