mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-30 09:57:52 +01:00
Merge pull request #593 from cyrildtm/fixUserLocalesUndefined
Restructure userLocales logic
This commit is contained in:
2 files changed
+44
-38
No files matched your search
@@ -461,32 +461,38 @@ function roundDown(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function numberFormat(numberState) {
|
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 {
|
|
||||||
userLocales = document.documentElement.lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
let numberDisplay;
|
let numberDisplay;
|
||||||
if (extConfig.numberDisplayRoundDown === false) {
|
if (extConfig.numberDisplayRoundDown === false) {
|
||||||
numberDisplay = numberState;
|
numberDisplay = numberState;
|
||||||
} else {
|
} else {
|
||||||
numberDisplay = roundDown(numberState);
|
numberDisplay = roundDown(numberState);
|
||||||
}
|
}
|
||||||
return getNumberFormatter(extConfig.numberDisplayFormat, userLocales).format(
|
return getNumberFormatter(extConfig.numberDisplayFormat).format(
|
||||||
numberDisplay
|
numberDisplay
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNumberFormatter(optionSelect, userLocales) {
|
function getNumberFormatter(optionSelect) {
|
||||||
|
let userLocales;
|
||||||
|
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 formatterNotation;
|
||||||
let formatterCompactDisplay;
|
let formatterCompactDisplay;
|
||||||
|
|
||||||
switch (optionSelect) {
|
switch (optionSelect) {
|
||||||
case "compactLong":
|
case "compactLong":
|
||||||
formatterNotation = "compact";
|
formatterNotation = "compact";
|
||||||
@@ -503,7 +509,7 @@ function getNumberFormatter(optionSelect, userLocales) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatter = Intl.NumberFormat(
|
const formatter = Intl.NumberFormat(
|
||||||
document.documentElement.lang || userLocales || navigator.language,
|
userLocales,
|
||||||
{
|
{
|
||||||
notation: formatterNotation,
|
notation: formatterNotation,
|
||||||
compactDisplay: formatterCompactDisplay,
|
compactDisplay: formatterCompactDisplay,
|
||||||
|
|||||||
@@ -9,15 +9,6 @@ function roundDown(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function numberFormat(numberState) {
|
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;
|
let numberDisplay;
|
||||||
if (extConfig.numberDisplayRoundDown === false) {
|
if (extConfig.numberDisplayRoundDown === false) {
|
||||||
numberDisplay = numberState;
|
numberDisplay = numberState;
|
||||||
@@ -29,22 +20,27 @@ function numberFormat(numberState) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function localize(localeString) {
|
|
||||||
return chrome.i18n.getMessage(localeString);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNumberFormatter(optionSelect) {
|
function getNumberFormatter(optionSelect) {
|
||||||
|
let userLocales;
|
||||||
|
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 formatterNotation;
|
||||||
let formatterCompactDisplay;
|
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 {}
|
|
||||||
|
|
||||||
switch (optionSelect) {
|
switch (optionSelect) {
|
||||||
case "compactLong":
|
case "compactLong":
|
||||||
formatterNotation = "compact";
|
formatterNotation = "compact";
|
||||||
@@ -61,7 +57,7 @@ function getNumberFormatter(optionSelect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatter = Intl.NumberFormat(
|
const formatter = Intl.NumberFormat(
|
||||||
document.documentElement.lang || userLocales || navigator.language,
|
userLocales,
|
||||||
{
|
{
|
||||||
notation: formatterNotation,
|
notation: formatterNotation,
|
||||||
compactDisplay: formatterCompactDisplay,
|
compactDisplay: formatterCompactDisplay,
|
||||||
@@ -70,6 +66,10 @@ function getNumberFormatter(optionSelect) {
|
|||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localize(localeString) {
|
||||||
|
return chrome.i18n.getMessage(localeString);
|
||||||
|
}
|
||||||
|
|
||||||
function getBrowser() {
|
function getBrowser() {
|
||||||
if (typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined") {
|
if (typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined") {
|
||||||
return chrome;
|
return chrome;
|
||||||
|
|||||||
Reference in new issue
Block a user