From 5c87cf1547258c8b20133eae6909f5365d96a981 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 19 Oct 2018 11:14:26 -0500 Subject: [PATCH] Update subscribe buttons --- src/invidious/helpers/utils.cr | 19 +++++++++++++++++++ src/invidious/views/channel.ecr | 8 ++++---- src/invidious/views/watch.ecr | 8 ++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 7ff2e622..dab8e0e9 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -138,6 +138,25 @@ def number_with_separator(number) number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse end +def number_to_short_text(number) + seperated = number_with_separator(number).gsub(",", ".").split("") + text = seperated.first(2).join + + if seperated[2]? && seperated[2] != "." + text += seperated[2] + end + + text = text.rchop(".0") + + if number / 1000000 != 0 + text += "M" + elsif number / 1000 != 0 + text += "K" + end + + text +end + def arg_array(array, start = 1) if array.size == 0 args = "NULL" diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr index 4a3997aa..475d3880 100644 --- a/src/invidious/views/channel.ecr +++ b/src/invidious/views/channel.ecr @@ -19,14 +19,14 @@

"> - Unsubscribe from <%= author %> <%= number_with_separator(sub_count) %> + Unsubscribe <%= number_to_short_text(sub_count) %>

<% else %>

"> - Subscribe to <%= author %> <%= number_with_separator(sub_count) %> + Subscribe <%= number_to_short_text(sub_count) %>

<% end %> @@ -82,7 +82,7 @@ function subscribe() { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = unsubscribe; - subscribe_button.innerHTML = 'Unsubscribe from <%= author %> <%= number_with_separator(sub_count + 1) %>' + subscribe_button.innerHTML = 'Unsubscribe <%= number_to_short_text(sub_count) %>' } } } @@ -101,7 +101,7 @@ function unsubscribe() { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = subscribe; - subscribe_button.innerHTML = 'Subscribe to <%= author %> <%= number_with_separator(sub_count) %>' + subscribe_button.innerHTML = 'Subscribe <%= number_to_short_text(sub_count) %>' } } } diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 456526f4..866b8bad 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -94,14 +94,14 @@

"> - Unsubscribe from <%= video.author %> <%= video.sub_count_text %> + Unsubscribe <%= video.sub_count_text %>

<% else %>

"> - Subscribe to <%= video.author %> <%= video.sub_count_text %> + Subscribe <%= video.sub_count_text %>

<% end %> @@ -170,7 +170,7 @@ function subscribe() { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = unsubscribe; - subscribe_button.innerHTML = 'Unsubscribe from <%= video.author %> <%= video.sub_count_text %>' + subscribe_button.innerHTML = 'Unsubscribe <%= video.sub_count_text %>' } } } @@ -189,7 +189,7 @@ function unsubscribe() { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = subscribe; - subscribe_button.innerHTML = 'Subscribe to <%= video.author %> <%= video.sub_count_text %>' + subscribe_button.innerHTML = 'Subscribe <%= video.sub_count_text %>' } } }