diff options
author | oSumAtrIX <johan.melkonyan1@web.de> | 2021-12-23 22:28:12 +0300 |
---|---|---|
committer | oSumAtrIX <johan.melkonyan1@web.de> | 2021-12-23 22:28:12 +0300 |
commit | a4916110a034c17268915b99d9dfa0969b56f730 (patch) | |
tree | 9407b3ac0421cf321ad9a06622f4b33c2da393aa | |
parent | afae1b346f1d9faa7acb79033a6e2ddbe0a2f308 (diff) |
Format numbers the same way as the extension for the UserScript
-rw-r--r-- | Extensions/UserScript/Return Youtube Dislike.user.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index 6b3e576..71e926d 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -311,22 +311,22 @@ function roundDown(num) { } function numberFormat(numberState) { - let localeURL = Array.from(document.querySelectorAll("head > link[rel='search']")) - ?.find((n) => n?.getAttribute("href")?.includes("?locale=")) - ?.getAttribute("href"); - - const userLocales = localeURL ? new URL(localeURL)?.searchParams?.get("locale") : document.body.lang; - + let userLocales; + try { + userLocales = new URL( + Array.from(document.querySelectorAll("head > link[rel='search']")) + ?.find((n) => n?.getAttribute("href")?.includes("?locale=")) + ?.getAttribute("href") + )?.searchParams?.get("locale"); + } catch {} const formatter = Intl.NumberFormat( document.documentElement.lang || userLocales || navigator.language, { notation: "compact", - minimumFractionDigits: 1, - maximumFractionDigits: 1, } ); - return formatter.format(roundDown(numberState)).replace(/\.0|,0/, ""); + return formatter.format(roundDown(numberState)); } function setEventListeners(evt) { |