diff options
author | Dmitrii Selivanov <selivano.d@gmail.com> | 2021-12-27 13:30:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-27 13:30:45 +0300 |
commit | 2475a701a4e4be29f1de34e7b45cc2da40e73cda (patch) | |
tree | 58d3284fd153993e23bf7a0bd73ffb40e4dbf4a4 | |
parent | 8ffbe2320ced6bf5e962f39dcfd101c4faff91d5 (diff) | |
parent | a4916110a034c17268915b99d9dfa0969b56f730 (diff) |
Merge pull request #366 from oSumAtrIX/format-dislikes
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) { |