mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-26 00:03:01 +01:00
checks for youtube locale and uses navigator.language as fallback
This commit is contained in:
1 parent
6da6e73698
commit
4ba6ef9f9e
3 files changed
+70
-50
No files matched your search
@@ -5,7 +5,7 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
if (!storedData) {
|
||||
var storedData = {
|
||||
dislikes: 0,
|
||||
previousState: NEUTRAL_STATE
|
||||
previousState: NEUTRAL_STATE,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -121,10 +121,10 @@ function setState() {
|
||||
}
|
||||
|
||||
function likeClicked() {
|
||||
if (storedData.previousState === 'disliked') {
|
||||
if (storedData.previousState === "disliked") {
|
||||
storedData.dislikes--;
|
||||
setDislikes(numberFormat(storedData.dislikes));
|
||||
storedData.previousState = 'liked';
|
||||
storedData.previousState = "liked";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ function setInitialState() {
|
||||
function getVideoId(url) {
|
||||
const urlObject = new URL(url);
|
||||
const pathname = urlObject.pathname;
|
||||
if (pathname.startsWith('/clips')) {
|
||||
if (pathname.startsWith("/clips")) {
|
||||
return document.querySelector("meta[itemprop='videoId']").content;
|
||||
} else {
|
||||
return urlObject.searchParams.get("v");
|
||||
@@ -174,10 +174,13 @@ function roundDown(num) {
|
||||
}
|
||||
|
||||
function numberFormat(numberState) {
|
||||
const userLocales = navigator.language;
|
||||
|
||||
const formatter = Intl.NumberFormat(userLocales, {
|
||||
notation: "compact"
|
||||
const userLocales = new URL(
|
||||
Array.from(document.querySelectorAll("head > link[rel='search']"))
|
||||
?.find((n) => n?.getAttribute("href")?.includes("?locale="))
|
||||
?.getAttribute("href")
|
||||
)?.searchParams?.get("locale");
|
||||
const formatter = Intl.NumberFormat(userLocales || navigator.language, {
|
||||
notation: "compact",
|
||||
});
|
||||
|
||||
return formatter.format(roundDown(numberState));
|
||||
|
||||
Reference in new issue
Block a user