From 783246abcd805fabcbb1fea27f2155293a9ce974 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 31 May 2021 03:36:35 +0530 Subject: [PATCH] Render like count textually. --- src/components/WatchVideo.vue | 2 +- src/main.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index d2888a25..2db7e5b1 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -63,7 +63,7 @@

{{ comment.commentText }}

- {{ comment.likeCount }} + {{ numberFormat(comment.likeCount) }}     diff --git a/src/main.js b/src/main.js index ec88fc6e..dcaaf273 100644 --- a/src/main.js +++ b/src/main.js @@ -33,6 +33,22 @@ const mixin = { return str; }, + numberFormat(num) { + const digits = 2; + const si = [ + { value: 1, symbol: "" }, + { value: 1E3, symbol: "k" }, + { value: 1E6, symbol: "M" }, + { value: 1E9, symbol: "B" } + ]; + const rx = /\.0+$|(\.[0-9]*[1-9])0+$/; + for (var i = si.length - 1; i > 0; i--) { + if (num >= si[i].value) { + break; + } + } + return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol; + }, fetchJson: function (url, options) { return fetch(url, options).then(response => { return response.json();