mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-29 09:27:54 +01:00
Merge branch 'main' into CustomNumberFormat
This commit is contained in:
29 files changed
+520
-91
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { getButtons } from "./buttons";
|
||||
import { likesDisabledState } from "./state";
|
||||
import { isMobile, likesDisabledState } from "./state";
|
||||
import { cLog } from "./utils";
|
||||
|
||||
function createRateBar(likes, dislikes) {
|
||||
@@ -14,7 +14,7 @@ function createRateBar(likes, dislikes) {
|
||||
const widthPercent =
|
||||
likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50;
|
||||
|
||||
if (!rateBar) {
|
||||
if (!rateBar && !isMobile()) {
|
||||
(
|
||||
document.getElementById("menu-container") ||
|
||||
document.querySelector("ytm-slim-video-action-bar-renderer")
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
import { isMobile } from "./state";
|
||||
import { isMobile, isShorts } from "./state";
|
||||
import { isInViewport } from "./utils";
|
||||
|
||||
function getButtons() {
|
||||
//--- If Watching Youtube Shorts: ---//
|
||||
if(isShorts()) {
|
||||
let elements=document.querySelectorAll(isMobile() ? "ytm-like-button-renderer" : "#like-button > ytd-like-button-renderer");
|
||||
for(let element of elements) {
|
||||
//Youtube Shorts can have multiple like/dislike buttons when scrolling through videos
|
||||
//However, only one of them should be visible (no matter how you zoom)
|
||||
if(isInViewport(element)) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
//--- If Watching On Mobile: ---//
|
||||
if (isMobile()) {
|
||||
return document.querySelector(".slim-video-action-bar-actions");
|
||||
}
|
||||
|
||||
@@ -100,6 +100,8 @@ function addLikeDislikeEventListener() {
|
||||
if (!window.returnDislikeButtonlistenersSet) {
|
||||
buttons.children[0].addEventListener("click", likeClicked);
|
||||
buttons.children[1].addEventListener("click", dislikeClicked);
|
||||
buttons.children[0].addEventListener("touchstart", likeClicked);
|
||||
buttons.children[1].addEventListener("touchstart", dislikeClicked);
|
||||
window.returnDislikeButtonlistenersSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ function isMobile() {
|
||||
return location.hostname == "m.youtube.com";
|
||||
}
|
||||
|
||||
function isShorts() {
|
||||
return location.pathname.startsWith("/shorts")
|
||||
}
|
||||
|
||||
function isVideoLiked() {
|
||||
if (isMobile()) {
|
||||
return (
|
||||
@@ -74,7 +78,7 @@ function setDislikes(dislikesCount) {
|
||||
}
|
||||
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
||||
} else {
|
||||
cLog("likes count diabled by creator");
|
||||
cLog("likes count disabled by creator");
|
||||
if (isMobile()) {
|
||||
getButtons().children[1].querySelector(
|
||||
".button-renderer-text"
|
||||
@@ -87,6 +91,11 @@ function setDislikes(dislikesCount) {
|
||||
}
|
||||
|
||||
function getLikeCountFromButton() {
|
||||
if(isShorts()) {
|
||||
//Youtube Shorts don't work with this query. It's not nessecary; we can skip it and still see the results.
|
||||
//It should be possible to fix this function, but it's not critical to showing the dislike count.
|
||||
return 0;
|
||||
}
|
||||
let likesStr = getLikeButton()
|
||||
.querySelector("button")
|
||||
.getAttribute("aria-label")
|
||||
@@ -181,6 +190,7 @@ function initializeNumberDisplayFormat() {
|
||||
|
||||
export {
|
||||
isMobile,
|
||||
isShorts,
|
||||
isVideoDisliked,
|
||||
isVideoLiked,
|
||||
getState,
|
||||
|
||||
@@ -78,10 +78,25 @@ function getVideoId(url) {
|
||||
if (pathname.startsWith("/clip")) {
|
||||
return document.querySelector("meta[itemprop='videoId']").content;
|
||||
} else {
|
||||
if (pathname.startsWith("/shorts")) {
|
||||
return pathname.substr(8);
|
||||
}
|
||||
return urlObject.searchParams.get("v");
|
||||
}
|
||||
}
|
||||
|
||||
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 isVideoLoaded() {
|
||||
const videoId = getVideoId(window.location.href);
|
||||
return (
|
||||
@@ -100,4 +115,4 @@ function cLog(message, writer) {
|
||||
}
|
||||
}
|
||||
|
||||
export { numberFormat, getBrowser, getVideoId, isVideoLoaded, cLog }
|
||||
export { numberFormat, getBrowser, getVideoId, isInViewport, isVideoLoaded, cLog }
|
||||
Reference in new issue
Block a user