mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 19:31:20 +01:00
UserScript: Supports YouTube Shorts
This commit is contained in:
1 parent
1cc579d00d
commit
0630627d3b
1 file changed
+26
-2
@@ -30,13 +30,34 @@ let likesvalue = 0;
|
|||||||
let dislikesvalue = 0;
|
let dislikesvalue = 0;
|
||||||
|
|
||||||
let isMobile = location.hostname == "m.youtube.com";
|
let isMobile = location.hostname == "m.youtube.com";
|
||||||
|
let isShorts = () => location.pathname.startsWith("/shorts")
|
||||||
let mobileDislikes = 0;
|
let mobileDislikes = 0;
|
||||||
function cLog(text, subtext = "") {
|
function cLog(text, subtext = "") {
|
||||||
subtext = subtext.trim() === "" ? "" : `(${subtext})`;
|
subtext = subtext.trim() === "" ? "" : `(${subtext})`;
|
||||||
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInViewport(element) {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const height = innerHeight || document.documentElement.clientHeight;
|
||||||
|
const width = innerWidth || document.documentElement.clientWidth;
|
||||||
|
return (
|
||||||
|
rect.top >= 0 &&
|
||||||
|
rect.left >= 0 &&
|
||||||
|
rect.bottom <= height &&
|
||||||
|
rect.right <= width
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function getButtons() {
|
function getButtons() {
|
||||||
|
if(isShorts()) {
|
||||||
|
let elements=document.querySelectorAll("#like-button > ytd-like-button-renderer");
|
||||||
|
for(let element of elements) {
|
||||||
|
if(isInViewport(element)) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return document.querySelector(".slim-video-action-bar-actions");
|
return document.querySelector(".slim-video-action-bar-actions");
|
||||||
}
|
}
|
||||||
@@ -214,6 +235,7 @@ function createRateBar(likes, dislikes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setState() {
|
function setState() {
|
||||||
cLog("Fetching votes...");
|
cLog("Fetching votes...");
|
||||||
let statsSet = false;
|
let statsSet = false;
|
||||||
@@ -232,7 +254,6 @@ function setState() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setState = function(){};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function likeClicked() {
|
function likeClicked() {
|
||||||
@@ -288,6 +309,9 @@ function getVideoId() {
|
|||||||
if (pathname.startsWith("/clip")) {
|
if (pathname.startsWith("/clip")) {
|
||||||
return document.querySelector("meta[itemprop='videoId']").content;
|
return document.querySelector("meta[itemprop='videoId']").content;
|
||||||
} else {
|
} else {
|
||||||
|
if (pathname.startsWith("/shorts")) {
|
||||||
|
return pathname.substr(8);
|
||||||
|
}
|
||||||
return urlObject.searchParams.get("v");
|
return urlObject.searchParams.get("v");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +359,7 @@ function setEventListeners(evt) {
|
|||||||
|
|
||||||
function checkForJS_Finish(check) {
|
function checkForJS_Finish(check) {
|
||||||
console.log();
|
console.log();
|
||||||
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
if (isShorts() || getButtons()?.offsetParent && isVideoLoaded()) {
|
||||||
clearInterval(jsInitChecktimer);
|
clearInterval(jsInitChecktimer);
|
||||||
const buttons = getButtons();
|
const buttons = getButtons();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user