mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-02 19:01:21 +01:00
Feat #211 fix whitespace
This commit is contained in:
1 parent
002995f0b5
commit
49d62522b6
1 file changed
+74
-75
@@ -24,8 +24,8 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
const extConfig = {
|
const extConfig = {
|
||||||
// BEGIN USER OPTIONS
|
// BEGIN USER OPTIONS
|
||||||
// You may change the following variables to allowed values listed in the corresponding brackets (* means default). Keep the style and keywords intact.
|
// You may change the following variables to allowed values listed in the corresponding brackets (* means default). Keep the style and keywords intact.
|
||||||
showUpdatePopup: false, // [true, false*] Show a popup tab after extension update (See what's new)
|
showUpdatePopup: false, // [true, false*] Show a popup tab after extension update (See what's new)
|
||||||
disableVoteSubmission: false, // [true, false*] Disable like/dislike submission (Stops counting your likes and dislikes)
|
disableVoteSubmission: false, // [true, false*] Disable like/dislike submission (Stops counting your likes and dislikes)
|
||||||
coloredThumbs: false, // [true, false*] Colorize thumbs (Use custom colors for thumb icons)
|
coloredThumbs: false, // [true, false*] Colorize thumbs (Use custom colors for thumb icons)
|
||||||
@@ -35,25 +35,25 @@ const extConfig = {
|
|||||||
numberDisplayRoundDown: true, // [true*, false] Round down numbers (Show rounded down numbers)
|
numberDisplayRoundDown: true, // [true*, false] Round down numbers (Show rounded down numbers)
|
||||||
tooltipPercentageMode: "none", // [none*, dash_like, dash_dislike, both, only_like, only_dislike] Mode of showing percentage in like/dislike bar tooltip.
|
tooltipPercentageMode: "none", // [none*, dash_like, dash_dislike, both, only_like, only_dislike] Mode of showing percentage in like/dislike bar tooltip.
|
||||||
numberDisplayReformatLikes: false, // [true, false*] Re-format like numbers (Make likes and dislikes format consistent)
|
numberDisplayReformatLikes: false, // [true, false*] Re-format like numbers (Make likes and dislikes format consistent)
|
||||||
// END USER OPTIONS
|
// END USER OPTIONS
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIKED_STATE = "LIKED_STATE";
|
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";
|
||||||
let previousState = 3; //1=LIKED, 2=DISLIKED, 3=NEUTRAL
|
let previousState = 3; //1=LIKED, 2=DISLIKED, 3=NEUTRAL
|
||||||
let likesvalue = 0;
|
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 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) {
|
function isInViewport(element) {
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
const height = innerHeight || document.documentElement.clientHeight;
|
const height = innerHeight || document.documentElement.clientHeight;
|
||||||
const width = innerWidth || document.documentElement.clientWidth;
|
const width = innerWidth || document.documentElement.clientWidth;
|
||||||
@@ -63,9 +63,9 @@ const extConfig = {
|
|||||||
rect.bottom <= height &&
|
rect.bottom <= height &&
|
||||||
rect.right <= width
|
rect.right <= width
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getButtons() {
|
function getButtons() {
|
||||||
if (isShorts()) {
|
if (isShorts()) {
|
||||||
let elements = document.querySelectorAll(
|
let elements = document.querySelectorAll(
|
||||||
isMobile
|
isMobile
|
||||||
@@ -88,19 +88,19 @@ const extConfig = {
|
|||||||
.getElementById("menu-container")
|
.getElementById("menu-container")
|
||||||
?.querySelector("#top-level-buttons-computed");
|
?.querySelector("#top-level-buttons-computed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLikeButton() {
|
function getLikeButton() {
|
||||||
return getButtons().children[0];
|
return getButtons().children[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDislikeButton() {
|
function getDislikeButton() {
|
||||||
return getButtons().children[1];
|
return getButtons().children[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
let mutationObserver = new Object();
|
let mutationObserver = new Object();
|
||||||
|
|
||||||
if (isShorts() && mutationObserver.exists !== true) {
|
if (isShorts() && mutationObserver.exists !== true) {
|
||||||
cLog('initializing mutation observer')
|
cLog('initializing mutation observer')
|
||||||
mutationObserver.options = {
|
mutationObserver.options = {
|
||||||
childList: false,
|
childList: false,
|
||||||
@@ -126,9 +126,9 @@ const extConfig = {
|
|||||||
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLiked() {
|
function isVideoLiked() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return (
|
return (
|
||||||
getLikeButton().querySelector("button").getAttribute("aria-label") ==
|
getLikeButton().querySelector("button").getAttribute("aria-label") ==
|
||||||
@@ -136,9 +136,9 @@ const extConfig = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return getLikeButton().classList.contains("style-default-active");
|
return getLikeButton().classList.contains("style-default-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoDisliked() {
|
function isVideoDisliked() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return (
|
return (
|
||||||
getDislikeButton().querySelector("button").getAttribute("aria-label") ==
|
getDislikeButton().querySelector("button").getAttribute("aria-label") ==
|
||||||
@@ -146,23 +146,23 @@ const extConfig = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return getDislikeButton().classList.contains("style-default-active");
|
return getDislikeButton().classList.contains("style-default-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotLiked() {
|
function isVideoNotLiked() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return !isVideoLiked();
|
return !isVideoLiked();
|
||||||
}
|
}
|
||||||
return getLikeButton().classList.contains("style-text");
|
return getLikeButton().classList.contains("style-text");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoNotDisliked() {
|
function isVideoNotDisliked() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return !isVideoDisliked();
|
return !isVideoDisliked();
|
||||||
}
|
}
|
||||||
return getDislikeButton().classList.contains("style-text");
|
return getDislikeButton().classList.contains("style-text");
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForUserAvatarButton() {
|
function checkForUserAvatarButton() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -171,9 +171,9 @@ const extConfig = {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
if (isVideoLiked()) {
|
if (isVideoLiked()) {
|
||||||
return LIKED_STATE;
|
return LIKED_STATE;
|
||||||
}
|
}
|
||||||
@@ -181,26 +181,26 @@ const extConfig = {
|
|||||||
return DISLIKED_STATE;
|
return DISLIKED_STATE;
|
||||||
}
|
}
|
||||||
return NEUTRAL_STATE;
|
return NEUTRAL_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLikes(likesCount) {
|
function setLikes(likesCount) {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
getButtons().children[0].querySelector(".button-renderer-text").innerText =
|
getButtons().children[0].querySelector(".button-renderer-text").innerText =
|
||||||
likesCount;
|
likesCount;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDislikes(dislikesCount) {
|
function setDislikes(dislikesCount) {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
mobileDislikes = dislikesCount;
|
mobileDislikes = dislikesCount;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLikeCountFromButton() {
|
function getLikeCountFromButton() {
|
||||||
if (isShorts()) {
|
if (isShorts()) {
|
||||||
//Youtube Shorts don't work with this query. It's not nessecary; we can skip it and still see the results.
|
//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.
|
//It should be possible to fix this function, but it's not critical to showing the dislike count.
|
||||||
@@ -211,9 +211,9 @@ const extConfig = {
|
|||||||
.getAttribute("aria-label")
|
.getAttribute("aria-label")
|
||||||
.replace(/\D/g, "");
|
.replace(/\D/g, "");
|
||||||
return likesStr.length > 0 ? parseInt(likesStr) : false;
|
return likesStr.length > 0 ? parseInt(likesStr) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(typeof GM_addStyle != "undefined"
|
(typeof GM_addStyle != "undefined"
|
||||||
? GM_addStyle
|
? GM_addStyle
|
||||||
: (styles) => {
|
: (styles) => {
|
||||||
let styleNode = document.createElement("style");
|
let styleNode = document.createElement("style");
|
||||||
@@ -249,7 +249,7 @@ const extConfig = {
|
|||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
function createRateBar(likes, dislikes) {
|
function createRateBar(likes, dislikes) {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ const extConfig = {
|
|||||||
<!--css-build:shady-->${tooltipInnerHTML}
|
<!--css-build:shady-->${tooltipInnerHTML}
|
||||||
</tp-yt-paper-tooltip>
|
</tp-yt-paper-tooltip>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
@@ -336,9 +336,9 @@ const extConfig = {
|
|||||||
getColorFromTheme(true);
|
getColorFromTheme(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setState() {
|
function setState() {
|
||||||
cLog("Fetching votes...");
|
cLog("Fetching votes...");
|
||||||
let statsSet = false;
|
let statsSet = false;
|
||||||
|
|
||||||
@@ -379,9 +379,9 @@ const extConfig = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function likeClicked() {
|
function likeClicked() {
|
||||||
if (checkForUserAvatarButton() == true) {
|
if (checkForUserAvatarButton() == true) {
|
||||||
if (previousState == 1) {
|
if (previousState == 1) {
|
||||||
likesvalue--;
|
likesvalue--;
|
||||||
@@ -400,9 +400,9 @@ const extConfig = {
|
|||||||
previousState = 1;
|
previousState = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dislikeClicked() {
|
function dislikeClicked() {
|
||||||
if (checkForUserAvatarButton() == true) {
|
if (checkForUserAvatarButton() == true) {
|
||||||
if (previousState == 3) {
|
if (previousState == 3) {
|
||||||
dislikesvalue++;
|
dislikesvalue++;
|
||||||
@@ -422,13 +422,13 @@ const extConfig = {
|
|||||||
previousState = 2;
|
previousState = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitialState() {
|
function setInitialState() {
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
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("/clip")) {
|
if (pathname.startsWith("/clip")) {
|
||||||
@@ -439,9 +439,9 @@ const extConfig = {
|
|||||||
}
|
}
|
||||||
return urlObject.searchParams.get("v");
|
return urlObject.searchParams.get("v");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLoaded() {
|
function isVideoLoaded() {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return document.getElementById("player").getAttribute("loading") == "false";
|
return document.getElementById("player").getAttribute("loading") == "false";
|
||||||
}
|
}
|
||||||
@@ -450,17 +450,17 @@ const extConfig = {
|
|||||||
return (
|
return (
|
||||||
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function roundDown(num) {
|
function roundDown(num) {
|
||||||
if (num < 1000) return num;
|
if (num < 1000) return num;
|
||||||
const int = Math.floor(Math.log10(num) - 2);
|
const int = Math.floor(Math.log10(num) - 2);
|
||||||
const decimal = int + (int % 3 ? 1 : 0);
|
const decimal = int + (int % 3 ? 1 : 0);
|
||||||
const value = Math.floor(num / 10 ** decimal);
|
const value = Math.floor(num / 10 ** decimal);
|
||||||
return value * 10 ** decimal;
|
return value * 10 ** decimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
function numberFormat(numberState) {
|
function numberFormat(numberState) {
|
||||||
let userLocales;
|
let userLocales;
|
||||||
try {
|
try {
|
||||||
userLocales = new URL(
|
userLocales = new URL(
|
||||||
@@ -479,9 +479,9 @@ const extConfig = {
|
|||||||
return getNumberFormatter(extConfig.numberDisplayFormat).format(
|
return getNumberFormatter(extConfig.numberDisplayFormat).format(
|
||||||
numberDisplay
|
numberDisplay
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNumberFormatter(optionSelect) {
|
function getNumberFormatter(optionSelect) {
|
||||||
let formatterNotation;
|
let formatterNotation;
|
||||||
let formatterCompactDisplay;
|
let formatterCompactDisplay;
|
||||||
|
|
||||||
@@ -508,9 +508,9 @@ const extConfig = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColorFromTheme(voteIsLike) {
|
function getColorFromTheme(voteIsLike) {
|
||||||
let colorString;
|
let colorString;
|
||||||
switch (extConfig.colorTheme) {
|
switch (extConfig.colorTheme) {
|
||||||
case "accessible":
|
case "accessible":
|
||||||
@@ -536,9 +536,9 @@ const extConfig = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return colorString;
|
return colorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEventListeners(evt) {
|
function setEventListeners(evt) {
|
||||||
let jsInitChecktimer;
|
let jsInitChecktimer;
|
||||||
|
|
||||||
function checkForJS_Finish(check) {
|
function checkForJS_Finish(check) {
|
||||||
@@ -565,14 +565,14 @@ const extConfig = {
|
|||||||
|
|
||||||
cLog("Setting up...");
|
cLog("Setting up...");
|
||||||
jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
||||||
}
|
}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
window.addEventListener("yt-navigate-finish", setEventListeners, true);
|
window.addEventListener("yt-navigate-finish", setEventListeners, true);
|
||||||
setEventListeners();
|
setEventListeners();
|
||||||
})();
|
})();
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
let originalPush = history.pushState;
|
let originalPush = history.pushState;
|
||||||
history.pushState = function (...args) {
|
history.pushState = function (...args) {
|
||||||
window.returnDislikeButtonlistenersSet = false;
|
window.returnDislikeButtonlistenersSet = false;
|
||||||
@@ -583,5 +583,4 @@ const extConfig = {
|
|||||||
getDislikeButton().querySelector(".button-renderer-text").innerText =
|
getDislikeButton().querySelector(".button-renderer-text").innerText =
|
||||||
mobileDislikes;
|
mobileDislikes;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user