mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-22 22:33:01 +01:00
move roundDown and numberFormat utils.js and import at origin
This commit is contained in:
1 parent
782cd1eab1
commit
3bc47f9e56
2 files changed
+29
-27
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
NEUTRAL_STATE,
|
||||
} from "./src/state";
|
||||
|
||||
import { numberFormat } from "./src/utils";
|
||||
|
||||
let storedData = {
|
||||
likes: 0,
|
||||
@@ -230,33 +231,6 @@ function sendVote(vote) {
|
||||
);
|
||||
}
|
||||
|
||||
function roundDown(num) {
|
||||
if (num < 1000) return num;
|
||||
const int = Math.floor(Math.log10(num) - 2);
|
||||
const decimal = int + (int % 3 ? 1 : 0);
|
||||
const value = Math.floor(num / 10 ** decimal);
|
||||
return value * 10 ** decimal;
|
||||
}
|
||||
|
||||
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 {}
|
||||
const formatter = Intl.NumberFormat(
|
||||
document.documentElement.lang || userLocales || navigator.language,
|
||||
{
|
||||
notation: "compact",
|
||||
}
|
||||
);
|
||||
|
||||
return formatter.format(roundDown(numberState));
|
||||
}
|
||||
|
||||
let jsInitChecktimer = null;
|
||||
|
||||
function setEventListeners(evt) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
function roundDown(num) {
|
||||
if (num < 1000) return num;
|
||||
const int = Math.floor(Math.log10(num) - 2);
|
||||
const decimal = int + (int % 3 ? 1 : 0);
|
||||
const value = Math.floor(num / 10 ** decimal);
|
||||
return value * 10 ** decimal;
|
||||
}
|
||||
|
||||
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 {}
|
||||
const formatter = Intl.NumberFormat(
|
||||
document.documentElement.lang || userLocales || navigator.language,
|
||||
{
|
||||
notation: "compact",
|
||||
}
|
||||
);
|
||||
|
||||
return formatter.format(roundDown(numberState));
|
||||
}
|
||||
|
||||
export { numberFormat }
|
||||
Reference in new issue
Block a user