|
@@ -9,15 +9,6 @@ function roundDown(num) {
|
|
|
}
|
|
|
|
|
|
function numberFormat(numberState) {
|
|
|
- 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 {}
|
|
|
-
|
|
|
let numberDisplay;
|
|
|
if (extConfig.numberDisplayRoundDown === false) {
|
|
|
numberDisplay = numberState;
|
|
@@ -29,22 +20,27 @@ function numberFormat(numberState) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-function localize(localeString) {
|
|
|
- return chrome.i18n.getMessage(localeString);
|
|
|
-}
|
|
|
-
|
|
|
function getNumberFormatter(optionSelect) {
|
|
|
- let formatterNotation;
|
|
|
- let formatterCompactDisplay;
|
|
|
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 {}
|
|
|
+ if (document.documentElement.lang) {
|
|
|
+ userLocales = document.documentElement.lang;
|
|
|
+ } else if (navigator.language) {
|
|
|
+ userLocales = navigator.language;
|
|
|
+ } else {
|
|
|
+ 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 {
|
|
|
+ cLog('Cannot find browser locale. Use en as default for number formatting.');
|
|
|
+ userLocales = 'en';
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ let formatterNotation;
|
|
|
+ let formatterCompactDisplay;
|
|
|
switch (optionSelect) {
|
|
|
case "compactLong":
|
|
|
formatterNotation = "compact";
|
|
@@ -61,7 +57,7 @@ function getNumberFormatter(optionSelect) {
|
|
|
}
|
|
|
|
|
|
const formatter = Intl.NumberFormat(
|
|
|
- document.documentElement.lang || userLocales || navigator.language,
|
|
|
+ userLocales,
|
|
|
{
|
|
|
notation: formatterNotation,
|
|
|
compactDisplay: formatterCompactDisplay,
|
|
@@ -70,6 +66,10 @@ function getNumberFormatter(optionSelect) {
|
|
|
return formatter;
|
|
|
}
|
|
|
|
|
|
+function localize(localeString) {
|
|
|
+ return chrome.i18n.getMessage(localeString);
|
|
|
+}
|
|
|
+
|
|
|
function getBrowser() {
|
|
|
if (typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined") {
|
|
|
return chrome;
|