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 @@
<% else %> <% 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 @@ <% else %> <% 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 %>' } } }