Browse Source

Merge pull request #281 from evanreichard/patch-2

[fix] YouTube Mobile Locale URL Doesn't Exist
Dmitrii Selivanov 3 years ago
parent
commit
78c7563410
1 changed files with 6 additions and 6 deletions
  1. 6 6
      Extensions/UserScript/Return Youtube Dislike.user.js

+ 6 - 6
Extensions/UserScript/Return Youtube Dislike.user.js

@@ -354,14 +354,14 @@ function roundDown(num) {
 }
 
 function numberFormat(numberState) {
-  const userLocales = new URL(
-    Array.from(document.querySelectorAll("head > link[rel='search']"))
-      ?.find((n) => n?.getAttribute("href")?.includes("?locale="))
-      ?.getAttribute("href")
-  )?.searchParams?.get("locale");
+  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;
 
   const formatter = Intl.NumberFormat(
-    document.documentElement.lang || userLocales,
+    document.documentElement.lang || userLocales || navigator.language,
     {
       notation: "compact",
       minimumFractionDigits: 1,