From f7125c12048d66b11c2dcf12d6f1bcde35ffaf3d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 6 Oct 2018 22:20:40 -0500 Subject: [PATCH] Move watch page JS into seperate file --- assets/js/watch.js | 48 ++++++++++++++++ src/invidious/comments.cr | 4 +- src/invidious/views/watch.ecr | 104 +++++++++------------------------- 3 files changed, 78 insertions(+), 78 deletions(-) create mode 100644 assets/js/watch.js diff --git a/assets/js/watch.js b/assets/js/watch.js new file mode 100644 index 000000000..7301f075a --- /dev/null +++ b/assets/js/watch.js @@ -0,0 +1,48 @@ +function toggle_parent(target) { + body = target.parentNode.parentNode.children[1]; + if (body.style.display === null || body.style.display === "") { + target.innerHTML = "[ + ]"; + body.style.display = "none"; + } else { + target.innerHTML = "[ - ]"; + body.style.display = ""; + } +} + +function toggle_comments(target) { + body = target.parentNode.parentNode.parentNode.children[1]; + if (body.style.display === null || body.style.display === "") { + target.innerHTML = "[ + ]"; + body.style.display = "none"; + } else { + target.innerHTML = "[ - ]"; + body.style.display = ""; + } +} + +function swap_comments(source) { + comments = document.getElementById("comments"); + var fallback = comments.innerHTML; + comments.innerHTML = + '

'; + + if (source == "youtube") { + get_youtube_comments(); + } else if (source == "reddit") { + get_reddit_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]; + return typeof r === "string" || typeof r === "number" ? r : a; + }); +}; diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index ec89c66bf..ccd0f8cb7 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -109,7 +109,7 @@ def template_youtube_comments(comments)

- [ - ] + [ - ] #{child["author"]} @@ -158,7 +158,7 @@ def template_reddit_comments(root) content = <<-END_HTML

- [ - ] + [ - ] #{author} #{score} points #{recode_date(child.created_utc)} ago diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 4f842c4cc..4eaaf9a66 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -22,6 +22,7 @@ + <%= rendered "components/player_sources" %> <%= HTML.escape(video.title) %> - Invidious <% end %> @@ -144,61 +145,6 @@