|
@@ -26,10 +26,10 @@ const LIKED_STATE = "LIKED_STATE";
|
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
|
|
|
|
|
-var isMobile = (location.hostname == "m.youtube.com");
|
|
|
|
|
|
+var isMobile = location.hostname == "m.youtube.com";
|
|
var mobileDislikes = 0;
|
|
var mobileDislikes = 0;
|
|
-function cLog(text, subtext = '') {
|
|
|
|
- subtext = subtext.trim() === '' ? '' : `(${subtext})`;
|
|
|
|
|
|
+function cLog(text, subtext = "") {
|
|
|
|
+ subtext = subtext.trim() === "" ? "" : `(${subtext})`;
|
|
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
|
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -56,14 +56,20 @@ function getDislikeButton() {
|
|
|
|
|
|
function isVideoLiked() {
|
|
function isVideoLiked() {
|
|
if (isMobile) {
|
|
if (isMobile) {
|
|
- return getLikeButton().querySelector("button").getAttribute("aria-label") == "true";
|
|
|
|
|
|
+ return (
|
|
|
|
+ getLikeButton().querySelector("button").getAttribute("aria-label") ==
|
|
|
|
+ "true"
|
|
|
|
+ );
|
|
}
|
|
}
|
|
return getLikeButton().classList.contains("style-default-active");
|
|
return getLikeButton().classList.contains("style-default-active");
|
|
}
|
|
}
|
|
|
|
|
|
function isVideoDisliked() {
|
|
function isVideoDisliked() {
|
|
if (isMobile) {
|
|
if (isMobile) {
|
|
- return getDislikeButton().querySelector("button").getAttribute("aria-label") == "true";
|
|
|
|
|
|
+ return (
|
|
|
|
+ getDislikeButton().querySelector("button").getAttribute("aria-label") ==
|
|
|
|
+ "true"
|
|
|
|
+ );
|
|
}
|
|
}
|
|
return getDislikeButton().classList.contains("style-default-active");
|
|
return getDislikeButton().classList.contains("style-default-active");
|
|
}
|
|
}
|
|
@@ -94,7 +100,8 @@ function getState() {
|
|
|
|
|
|
function setLikes(likesCount) {
|
|
function setLikes(likesCount) {
|
|
if (isMobile) {
|
|
if (isMobile) {
|
|
- getButtons().children[0].querySelector(".button-renderer-text").innerText = likesCount;
|
|
|
|
|
|
+ getButtons().children[0].querySelector(".button-renderer-text").innerText =
|
|
|
|
+ likesCount;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
|
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
|
@@ -108,14 +115,14 @@ function setDislikes(dislikesCount) {
|
|
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
|
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
|
}
|
|
}
|
|
|
|
|
|
-(typeof GM_addStyle != 'undefined'
|
|
|
|
- ? GM_addStyle
|
|
|
|
- : styles => {
|
|
|
|
- var styleNode = document.createElement("style")
|
|
|
|
- styleNode.type = "text/css";
|
|
|
|
- styleNode.innerText = styles;
|
|
|
|
- document.head.appendChild(styleNode);
|
|
|
|
-})(`
|
|
|
|
|
|
+(typeof GM_addStyle != "undefined"
|
|
|
|
+ ? GM_addStyle
|
|
|
|
+ : (styles) => {
|
|
|
|
+ var styleNode = document.createElement("style");
|
|
|
|
+ styleNode.type = "text/css";
|
|
|
|
+ styleNode.innerText = styles;
|
|
|
|
+ document.head.appendChild(styleNode);
|
|
|
|
+ })(`
|
|
#return-youtube-dislike-bar-container {
|
|
#return-youtube-dislike-bar-container {
|
|
background: var(--yt-spec-icon-disabled);
|
|
background: var(--yt-spec-icon-disabled);
|
|
border-radius: 2px;
|
|
border-radius: 2px;
|
|
@@ -201,7 +208,8 @@ function setState() {
|
|
method: "GET",
|
|
method: "GET",
|
|
url: `https://youtube.com/watch?v=${getVideoId()}`,
|
|
url: `https://youtube.com/watch?v=${getVideoId()}`,
|
|
headers: {
|
|
headers: {
|
|
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.3674"
|
|
|
|
|
|
+ "User-Agent":
|
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.3674",
|
|
},
|
|
},
|
|
onload: (response) => {
|
|
onload: (response) => {
|
|
let result = getDislikesFromYoutubeResponse(response.responseText);
|
|
let result = getDislikesFromYoutubeResponse(response.responseText);
|
|
@@ -215,10 +223,9 @@ function setState() {
|
|
statsSet = true;
|
|
statsSet = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
});
|
|
});
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
fetch(`https://youtube.com/watch?v=${getVideoId()}`).then((response) => {
|
|
fetch(`https://youtube.com/watch?v=${getVideoId()}`).then((response) => {
|
|
response.text().then((text) => {
|
|
response.text().then((text) => {
|
|
let result = getDislikesFromYoutubeResponse(text);
|
|
let result = getDislikesFromYoutubeResponse(text);
|
|
@@ -267,7 +274,7 @@ function setInitialState() {
|
|
function getVideoId() {
|
|
function getVideoId() {
|
|
const urlObject = new URL(window.location.href);
|
|
const urlObject = new URL(window.location.href);
|
|
const pathname = urlObject.pathname;
|
|
const pathname = urlObject.pathname;
|
|
- if (pathname.startsWith('/clips')) {
|
|
|
|
|
|
+ if (pathname.startsWith("/clips")) {
|
|
return document.querySelector("meta[itemprop='videoId']").content;
|
|
return document.querySelector("meta[itemprop='videoId']").content;
|
|
} else {
|
|
} else {
|
|
return urlObject.searchParams.get("v");
|
|
return urlObject.searchParams.get("v");
|
|
@@ -294,13 +301,20 @@ function roundDown(num) {
|
|
}
|
|
}
|
|
|
|
|
|
function numberFormat(numberState) {
|
|
function numberFormat(numberState) {
|
|
- const userLocales = document.documentElement.lang;
|
|
|
|
-
|
|
|
|
- const formatter = Intl.NumberFormat(userLocales, {
|
|
|
|
- notation: "compact",
|
|
|
|
- minimumFractionDigits: 1,
|
|
|
|
- maximumFractionDigits: 1,
|
|
|
|
- });
|
|
|
|
|
|
+ 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 || document.documentElement.lang,
|
|
|
|
+ {
|
|
|
|
+ notation: "compact",
|
|
|
|
+ minimumFractionDigits: 1,
|
|
|
|
+ maximumFractionDigits: 1,
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
|
|
return formatter.format(roundDown(numberState)).replace(/\.0|,0/, "");
|
|
return formatter.format(roundDown(numberState)).replace(/\.0|,0/, "");
|
|
}
|
|
}
|
|
@@ -338,7 +352,7 @@ function getDislikesFromYoutubeResponse(htmlResponse) {
|
|
|
|
|
|
function setEventListeners(evt) {
|
|
function setEventListeners(evt) {
|
|
function checkForJS_Finish(check) {
|
|
function checkForJS_Finish(check) {
|
|
- console.log()
|
|
|
|
|
|
+ console.log();
|
|
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
|
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
|
clearInterval(jsInitChecktimer);
|
|
clearInterval(jsInitChecktimer);
|
|
const buttons = getButtons();
|
|
const buttons = getButtons();
|
|
@@ -353,7 +367,10 @@ function setEventListeners(evt) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (window.location.href.indexOf("watch?") >= 0 || (isMobile && evt?.indexOf("watch?") >= 0)) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ window.location.href.indexOf("watch?") >= 0 ||
|
|
|
|
+ (isMobile && evt?.indexOf("watch?") >= 0)
|
|
|
|
+ ) {
|
|
cLog("Setting up...");
|
|
cLog("Setting up...");
|
|
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
|
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
|
}
|
|
}
|
|
@@ -370,8 +387,9 @@ if (isMobile) {
|
|
window.returnDislikeButtonlistenersSet = false;
|
|
window.returnDislikeButtonlistenersSet = false;
|
|
setEventListeners(args[2]);
|
|
setEventListeners(args[2]);
|
|
return originalPush.apply(history, args);
|
|
return originalPush.apply(history, args);
|
|
- }
|
|
|
|
|
|
+ };
|
|
setInterval(() => {
|
|
setInterval(() => {
|
|
- getDislikeButton().querySelector(".button-renderer-text").innerText = mobileDislikes;
|
|
|
|
|
|
+ getDislikeButton().querySelector(".button-renderer-text").innerText =
|
|
|
|
+ mobileDislikes;
|
|
}, 1000);
|
|
}, 1000);
|
|
}
|
|
}
|