mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-23 06:43:02 +01:00
Merge branch 'main' into main
This commit is contained in:
3 files changed
+22
-19
No files matched your search
@@ -40,7 +40,7 @@ function getButtons() {
|
||||
if (isMobile) {
|
||||
return document.querySelector(".slim-video-action-bar-actions");
|
||||
}
|
||||
if (document.getElementById("menu-container").offsetParent === null) {
|
||||
if (document.getElementById("menu-container")?.offsetParent === null) {
|
||||
return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
|
||||
} else {
|
||||
return document
|
||||
@@ -303,10 +303,13 @@ function setInitialState() {
|
||||
}
|
||||
|
||||
function getVideoId() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const videoId = urlParams.get("v");
|
||||
|
||||
return videoId;
|
||||
const urlObject = new URL(window.location.href);
|
||||
const pathname = urlObject.pathname;
|
||||
if (pathname.startsWith('/clips')) {
|
||||
return document.querySelector("meta[itemprop='videoId']").content;
|
||||
} else {
|
||||
return urlObject.searchParams.get("v");
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoLoaded() {
|
||||
|
||||
@@ -21,11 +21,11 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
function getButtons() {
|
||||
|
||||
//--- If Menu Element Is Displayed: ---//
|
||||
if (document.getElementById('menu-container').offsetParent === null) {
|
||||
if (document.getElementById('menu-container')?.offsetParent === null) {
|
||||
return document.querySelector(
|
||||
"ytd-menu-renderer.ytd-watch-metadata > div"
|
||||
);
|
||||
//--- If Menu Element Isnt Displayed: ---//
|
||||
//--- If Menu Element Isnt Displayed: ---//
|
||||
} else {
|
||||
return document
|
||||
.getElementById("menu-container")
|
||||
@@ -59,12 +59,12 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
|
||||
function getState() {
|
||||
if (isVideoLiked()) {
|
||||
return {current: LIKED_STATE, previous: storedData.previousState};
|
||||
return { current: LIKED_STATE, previous: storedData.previousState };
|
||||
}
|
||||
if (isVideoDisliked()) {
|
||||
return {current: DISLIKED_STATE, previous: storedData.previousState};
|
||||
return { current: DISLIKED_STATE, previous: storedData.previousState };
|
||||
}
|
||||
return {current: NEUTRAL_STATE, previous: storedData.previousState};
|
||||
return { current: NEUTRAL_STATE, previous: storedData.previousState };
|
||||
}
|
||||
|
||||
//--- Sets The Likes And Dislikes Values ---//
|
||||
@@ -90,7 +90,7 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
cLog("response from youtube:");
|
||||
cLog(JSON.stringify(response));
|
||||
try {
|
||||
if (response.viewCount) {
|
||||
if ("likes" in response && "dislikes" in response) {
|
||||
const formattedDislike = numberFormat(response.dislikes);
|
||||
setDislikes(formattedDislike);
|
||||
storedData.dislikes = parseInt(response.dislikes);
|
||||
@@ -115,7 +115,7 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
function (response) {
|
||||
cLog("response from api:");
|
||||
cLog(JSON.stringify(response));
|
||||
if (response != undefined && !statsSet) {
|
||||
if (response != undefined && !("traceId" in response) && !statsSet) {
|
||||
const formattedDislike = numberFormat(response.dislikes);
|
||||
// setLikes(response.likes);
|
||||
setDislikes(formattedDislike);
|
||||
@@ -148,7 +148,7 @@ const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
function dislikeClicked() {
|
||||
//let state = getState().current;
|
||||
|
||||
console.log("Dislike State:",getState());
|
||||
console.log("Dislike State:", getState());
|
||||
|
||||
if (storedData.previousState == NEUTRAL_STATE) {
|
||||
storedData.dislikes++;
|
||||
|
||||
@@ -21,7 +21,7 @@ function cLog(message, writer) {
|
||||
|
||||
function getButtons() {
|
||||
//--- If Menu Element Is Displayed: ---//
|
||||
if (document.getElementById("menu-container").offsetParent === null) {
|
||||
if (document.getElementById("menu-container")?.offsetParent === null) {
|
||||
return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
|
||||
//--- If Menu Element Isnt Displayed: ---//
|
||||
} else {
|
||||
@@ -57,12 +57,12 @@ function isVideoNotDisliked() {
|
||||
|
||||
function getState() {
|
||||
if (isVideoLiked()) {
|
||||
return {current: LIKED_STATE, previous: storedData.previousState};
|
||||
return { current: LIKED_STATE, previous: storedData.previousState };
|
||||
}
|
||||
if (isVideoDisliked()) {
|
||||
return {current: DISLIKED_STATE, previous: storedData.previousState};
|
||||
return { current: DISLIKED_STATE, previous: storedData.previousState };
|
||||
}
|
||||
return {current: NEUTRAL_STATE, previous: storedData.previousState};
|
||||
return { current: NEUTRAL_STATE, previous: storedData.previousState };
|
||||
}
|
||||
|
||||
//--- Sets The Likes And Dislikes Values ---//
|
||||
@@ -85,7 +85,7 @@ function setState() {
|
||||
cLog("response from youtube:");
|
||||
cLog(JSON.stringify(response));
|
||||
try {
|
||||
if (response.viewCount) {
|
||||
if ("likes" in response && "dislikes" in response) {
|
||||
const formattedDislike = numberFormat(response.dislikes);
|
||||
setDislikes(formattedDislike);
|
||||
storedData.dislikes = parseInt(response.dislikes);
|
||||
@@ -109,7 +109,7 @@ function setState() {
|
||||
function (response) {
|
||||
cLog("response from api:");
|
||||
cLog(JSON.stringify(response));
|
||||
if (response != undefined && !statsSet) {
|
||||
if (response != undefined && !("traceId" in response) && !statsSet) {
|
||||
const formattedDislike = numberFormat(response.dislikes);
|
||||
storedData.dislikes = response.dislikes;
|
||||
// setLikes(response.likes);
|
||||
|
||||
Reference in new issue
Block a user