diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-08-17 09:25:47 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-08-17 09:25:47 -0500 |
| commit | 71aa4d0347bb082caab0f2efea031ab33ff4174e (patch) | |
| tree | b8986d0600c32741c33703487f58fc2156b6f5b3 /src | |
| parent | fa2ba807a3ad16b3fd84bb24eb4610ff3c397063 (diff) | |
| download | invidious-71aa4d0347bb082caab0f2efea031ab33ff4174e.tar.gz invidious-71aa4d0347bb082caab0f2efea031ab33ff4174e.tar.bz2 invidious-71aa4d0347bb082caab0f2efea031ab33ff4174e.zip | |
Replace duplicate link to YouTube
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 13 | ||||
| -rw-r--r-- | src/invidious/views/watch.ecr | 20 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 616af019..4b3c473e 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1685,7 +1685,7 @@ get "/api/v1/comments/:id" do |env| if format == "json" next {"comments" => [] of String}.to_json else - next {"content_html" => ""}.to_json + next {"contentHtml" => ""}.to_json end end ctoken = ctoken["ctoken"] @@ -1723,7 +1723,7 @@ get "/api/v1/comments/:id" do |env| if format == "json" next {"comments" => [] of String}.to_json else - next {"content_html" => ""}.to_json + next {"contentHtml" => ""}.to_json end end @@ -1823,7 +1823,8 @@ get "/api/v1/comments/:id" do |env| comments = JSON.parse(comments) content_html = template_youtube_comments(comments) - next {"content_html" => content_html}.to_json + next {"contentHtml" => content_html, + "commentCount" => comments["commentCount"]}.to_json end elsif source == "reddit" client = make_client(REDDIT_URL) @@ -1844,9 +1845,9 @@ get "/api/v1/comments/:id" do |env| end env.response.content_type = "application/json" - next {"title" => reddit_thread.title, - "permalink" => reddit_thread.permalink, - "content_html" => content_html}.to_json + next {"title" => reddit_thread.title, + "permalink" => reddit_thread.permalink, + "contentHtml" => content_html}.to_json end end diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index cd757f5c..c09da851 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -72,7 +72,7 @@ function load_comments(target) { xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { - body.innerHTML = xhr.response.content_html; + body.innerHTML = xhr.response.contentHtml; } else { body.innerHTML = fallback; } @@ -106,12 +106,12 @@ function get_reddit_comments() { <a target="_blank" href="https://reddit.com{permalink}">View more comments on Reddit</a> </b> </div> - <div>{content_html}</div> + <div>{contentHtml}</div> <hr>`.supplant({ title: xhr.response.title, permalink: xhr.response.permalink, - content_html: xhr.response.content_html + contentHtml: xhr.response.contentHtml }); } else { get_youtube_comments(); @@ -139,12 +139,13 @@ function get_youtube_comments() { <div> <h3> <a href="javascript:void(0)" onclick="toggle_comments(this)">[ - ]</a> - <a target="_blank" href="https://www.youtube.com/watch?v=<%= video.id %>">View more comments on YouTube</a> + View {commentCount} comments </h3> </div> - <div>{content_html}</div> + <div>{contentHtml}</div> <hr>`.supplant({ - content_html: xhr.response.content_html + contentHtml: xhr.response.contentHtml, + commentCount: commaSeparateNumber(xhr.response.commentCount) }); } else { comments = document.getElementById("comments"); @@ -160,6 +161,13 @@ function get_youtube_comments() { }; } +function commaSeparateNumber(val){ + while (/(\d+)(\d{3})/.test(val.toString())){ + val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2'); + } + return val; +} + String.prototype.supplant = function(o) { return this.replace(/{([^{}]*)}/g, function(a, b) { var r = o[b]; |
