From 5d8b1723ebd7080dbe79f7e6276b9af713f3252e Mon Sep 17 00:00:00 2001 From: j14-c <> Date: Fri, 26 Nov 2021 09:47:46 -0500 Subject: [PATCH] modified numberFormat to round down and include decimals --- .../UserScript/Return Youtube Dislike.user.js | 16 ++++++++++++++-- .../chrome/return-youtube-dislike.script.js | 17 +++++++++++++++-- .../firefox/return-youtube-dislike.script.js | 17 +++++++++++++++-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index ec64dfe..92a3da8 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -137,11 +137,23 @@ function isVideoLoaded() { ); } +function roundDown(num) { + if (num < 1000) return num; + const decimal = Math.floor(Math.log10(num) - 1); + const value = Math.floor(num / 10 ** decimal); + return value * (10 ** decimal); +} + function numberFormat(numberState) { const userLocales = navigator.language; - const formatter = Intl.NumberFormat(userLocales, { notation: "compact" }); - return formatter.format(numberState); + const formatter = Intl.NumberFormat(userLocales, { + notation: 'compact', + minimumFractionDigits: 1, + maximumFractionDigits: 1 + }); + + return formatter.format(roundDown(numberState)).replace('.0', ''); } function setEventListeners(evt) { diff --git a/Extensions/chrome/return-youtube-dislike.script.js b/Extensions/chrome/return-youtube-dislike.script.js index 6a148f7..5ec0172 100644 --- a/Extensions/chrome/return-youtube-dislike.script.js +++ b/Extensions/chrome/return-youtube-dislike.script.js @@ -137,10 +137,23 @@ ); } + function roundDown(num) { + if (num < 1000) return num; + const decimal = Math.floor(Math.log10(num) - 1); + const value = Math.floor(num / 10 ** decimal); + return value * (10 ** decimal); + } + function numberFormat(numberState) { const userLocales = navigator.language; - const formatter = Intl.NumberFormat(userLocales, { notation: "compact" }); - return formatter.format(numberState); + + const formatter = Intl.NumberFormat(userLocales, { + notation: 'compact', + minimumFractionDigits: 1, + maximumFractionDigits: 1 + }); + + return formatter.format(roundDown(numberState)).replace('.0', ''); } var jsInitChecktimer = null; diff --git a/Extensions/firefox/return-youtube-dislike.script.js b/Extensions/firefox/return-youtube-dislike.script.js index 058a38b..2597ee2 100644 --- a/Extensions/firefox/return-youtube-dislike.script.js +++ b/Extensions/firefox/return-youtube-dislike.script.js @@ -133,10 +133,23 @@ function isVideoLoaded() { ); } +function roundDown(num) { + if (num < 1000) return num; + const decimal = Math.floor(Math.log10(num) - 1); + const value = Math.floor(num / 10 ** decimal); + return value * (10 ** decimal); +} + function numberFormat(numberState) { const userLocales = navigator.language; - const formatter = Intl.NumberFormat(userLocales, { notation: "compact" }); - return formatter.format(numberState); + + const formatter = Intl.NumberFormat(userLocales, { + notation: 'compact', + minimumFractionDigits: 1, + maximumFractionDigits: 1 + }); + + return formatter.format(roundDown(numberState)).replace('.0', ''); } function setEventListeners(evt) {