mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-04 11:51:20 +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==
|
||||
|
||||
const extConfig = {
|
||||
// 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.
|
||||
// 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.
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
// END USER OPTIONS
|
||||
};
|
||||
// END USER OPTIONS
|
||||
};
|
||||
|
||||
const LIKED_STATE = "LIKED_STATE";
|
||||
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
let previousState = 3; //1=LIKED, 2=DISLIKED, 3=NEUTRAL
|
||||
let likesvalue = 0;
|
||||
let dislikesvalue = 0;
|
||||
const LIKED_STATE = "LIKED_STATE";
|
||||
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
let previousState = 3; //1=LIKED, 2=DISLIKED, 3=NEUTRAL
|
||||
let likesvalue = 0;
|
||||
let dislikesvalue = 0;
|
||||
|
||||
let isMobile = location.hostname == "m.youtube.com";
|
||||
let isShorts = () => location.pathname.startsWith("/shorts");
|
||||
let mobileDislikes = 0;
|
||||
function cLog(text, subtext = "") {
|
||||
let isMobile = location.hostname == "m.youtube.com";
|
||||
let isShorts = () => location.pathname.startsWith("/shorts");
|
||||
let mobileDislikes = 0;
|
||||
function cLog(text, subtext = "") {
|
||||
subtext = subtext.trim() === "" ? "" : `(${subtext})`;
|
||||
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
||||
}
|
||||
}
|
||||
|
||||
function isInViewport(element) {
|
||||
function isInViewport(element) {
|
||||
const rect = element.getBoundingClientRect();
|
||||
const height = innerHeight || document.documentElement.clientHeight;
|
||||
const width = innerWidth || document.documentElement.clientWidth;
|
||||
@@ -63,9 +63,9 @@ const extConfig = {
|
||||
rect.bottom <= height &&
|
||||
rect.right <= width
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getButtons() {
|
||||
function getButtons() {
|
||||
if (isShorts()) {
|
||||
let elements = document.querySelectorAll(
|
||||
isMobile
|
||||
@@ -88,19 +88,19 @@ const extConfig = {
|
||||
.getElementById("menu-container")
|
||||
?.querySelector("#top-level-buttons-computed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLikeButton() {
|
||||
function getLikeButton() {
|
||||
return getButtons().children[0];
|
||||
}
|
||||
}
|
||||
|
||||
function getDislikeButton() {
|
||||
function getDislikeButton() {
|
||||
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')
|
||||
mutationObserver.options = {
|
||||
childList: false,
|
||||
@@ -126,9 +126,9 @@ const extConfig = {
|
||||
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoLiked() {
|
||||
function isVideoLiked() {
|
||||
if (isMobile) {
|
||||
return (
|
||||
getLikeButton().querySelector("button").getAttribute("aria-label") ==
|
||||
@@ -136,9 +136,9 @@ const extConfig = {
|
||||
);
|
||||
}
|
||||
return getLikeButton().classList.contains("style-default-active");
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoDisliked() {
|
||||
function isVideoDisliked() {
|
||||
if (isMobile) {
|
||||
return (
|
||||
getDislikeButton().querySelector("button").getAttribute("aria-label") ==
|
||||
@@ -146,23 +146,23 @@ const extConfig = {
|
||||
);
|
||||
}
|
||||
return getDislikeButton().classList.contains("style-default-active");
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoNotLiked() {
|
||||
function isVideoNotLiked() {
|
||||
if (isMobile) {
|
||||
return !isVideoLiked();
|
||||
}
|
||||
return getLikeButton().classList.contains("style-text");
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoNotDisliked() {
|
||||
function isVideoNotDisliked() {
|
||||
if (isMobile) {
|
||||
return !isVideoDisliked();
|
||||
}
|
||||
return getDislikeButton().classList.contains("style-text");
|
||||
}
|
||||
}
|
||||
|
||||
function checkForUserAvatarButton() {
|
||||
function checkForUserAvatarButton() {
|
||||
if (isMobile) {
|
||||
return;
|
||||
}
|
||||
@@ -171,9 +171,9 @@ const extConfig = {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getState() {
|
||||
function getState() {
|
||||
if (isVideoLiked()) {
|
||||
return LIKED_STATE;
|
||||
}
|
||||
@@ -181,26 +181,26 @@ const extConfig = {
|
||||
return DISLIKED_STATE;
|
||||
}
|
||||
return NEUTRAL_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
function setLikes(likesCount) {
|
||||
function setLikes(likesCount) {
|
||||
if (isMobile) {
|
||||
getButtons().children[0].querySelector(".button-renderer-text").innerText =
|
||||
likesCount;
|
||||
return;
|
||||
}
|
||||
getButtons().children[0].querySelector("#text").innerText = likesCount;
|
||||
}
|
||||
}
|
||||
|
||||
function setDislikes(dislikesCount) {
|
||||
function setDislikes(dislikesCount) {
|
||||
if (isMobile) {
|
||||
mobileDislikes = dislikesCount;
|
||||
return;
|
||||
}
|
||||
getButtons().children[1].querySelector("#text").innerText = dislikesCount;
|
||||
}
|
||||
}
|
||||
|
||||
function getLikeCountFromButton() {
|
||||
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.
|
||||
@@ -211,9 +211,9 @@ const extConfig = {
|
||||
.getAttribute("aria-label")
|
||||
.replace(/\D/g, "");
|
||||
return likesStr.length > 0 ? parseInt(likesStr) : false;
|
||||
}
|
||||
}
|
||||
|
||||
(typeof GM_addStyle != "undefined"
|
||||
(typeof GM_addStyle != "undefined"
|
||||
? GM_addStyle
|
||||
: (styles) => {
|
||||
let styleNode = document.createElement("style");
|
||||
@@ -249,7 +249,7 @@ const extConfig = {
|
||||
}
|
||||
`);
|
||||
|
||||
function createRateBar(likes, dislikes) {
|
||||
function createRateBar(likes, dislikes) {
|
||||
if (isMobile) {
|
||||
return;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ const extConfig = {
|
||||
<!--css-build:shady-->${tooltipInnerHTML}
|
||||
</tp-yt-paper-tooltip>
|
||||
</div>
|
||||
`
|
||||
`
|
||||
);
|
||||
} else {
|
||||
document.getElementById(
|
||||
@@ -336,9 +336,9 @@ const extConfig = {
|
||||
getColorFromTheme(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setState() {
|
||||
function setState() {
|
||||
cLog("Fetching votes...");
|
||||
let statsSet = false;
|
||||
|
||||
@@ -379,9 +379,9 @@ const extConfig = {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function likeClicked() {
|
||||
function likeClicked() {
|
||||
if (checkForUserAvatarButton() == true) {
|
||||
if (previousState == 1) {
|
||||
likesvalue--;
|
||||
@@ -400,9 +400,9 @@ const extConfig = {
|
||||
previousState = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dislikeClicked() {
|
||||
function dislikeClicked() {
|
||||
if (checkForUserAvatarButton() == true) {
|
||||
if (previousState == 3) {
|
||||
dislikesvalue++;
|
||||
@@ -422,13 +422,13 @@ const extConfig = {
|
||||
previousState = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setInitialState() {
|
||||
function setInitialState() {
|
||||
setState();
|
||||
}
|
||||
}
|
||||
|
||||
function getVideoId() {
|
||||
function getVideoId() {
|
||||
const urlObject = new URL(window.location.href);
|
||||
const pathname = urlObject.pathname;
|
||||
if (pathname.startsWith("/clip")) {
|
||||
@@ -439,9 +439,9 @@ const extConfig = {
|
||||
}
|
||||
return urlObject.searchParams.get("v");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isVideoLoaded() {
|
||||
function isVideoLoaded() {
|
||||
if (isMobile) {
|
||||
return document.getElementById("player").getAttribute("loading") == "false";
|
||||
}
|
||||
@@ -450,17 +450,17 @@ const extConfig = {
|
||||
return (
|
||||
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function roundDown(num) {
|
||||
function roundDown(num) {
|
||||
if (num < 1000) return num;
|
||||
const int = Math.floor(Math.log10(num) - 2);
|
||||
const decimal = int + (int % 3 ? 1 : 0);
|
||||
const value = Math.floor(num / 10 ** decimal);
|
||||
return value * 10 ** decimal;
|
||||
}
|
||||
}
|
||||
|
||||
function numberFormat(numberState) {
|
||||
function numberFormat(numberState) {
|
||||
let userLocales;
|
||||
try {
|
||||
userLocales = new URL(
|
||||
@@ -479,9 +479,9 @@ const extConfig = {
|
||||
return getNumberFormatter(extConfig.numberDisplayFormat).format(
|
||||
numberDisplay
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getNumberFormatter(optionSelect) {
|
||||
function getNumberFormatter(optionSelect) {
|
||||
let formatterNotation;
|
||||
let formatterCompactDisplay;
|
||||
|
||||
@@ -508,9 +508,9 @@ const extConfig = {
|
||||
}
|
||||
);
|
||||
return formatter;
|
||||
}
|
||||
}
|
||||
|
||||
function getColorFromTheme(voteIsLike) {
|
||||
function getColorFromTheme(voteIsLike) {
|
||||
let colorString;
|
||||
switch (extConfig.colorTheme) {
|
||||
case "accessible":
|
||||
@@ -536,9 +536,9 @@ const extConfig = {
|
||||
}
|
||||
}
|
||||
return colorString;
|
||||
}
|
||||
}
|
||||
|
||||
function setEventListeners(evt) {
|
||||
function setEventListeners(evt) {
|
||||
let jsInitChecktimer;
|
||||
|
||||
function checkForJS_Finish(check) {
|
||||
@@ -565,14 +565,14 @@ const extConfig = {
|
||||
|
||||
cLog("Setting up...");
|
||||
jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
||||
}
|
||||
}
|
||||
|
||||
(function () {
|
||||
(function () {
|
||||
"use strict";
|
||||
window.addEventListener("yt-navigate-finish", setEventListeners, true);
|
||||
setEventListeners();
|
||||
})();
|
||||
if (isMobile) {
|
||||
})();
|
||||
if (isMobile) {
|
||||
let originalPush = history.pushState;
|
||||
history.pushState = function (...args) {
|
||||
window.returnDislikeButtonlistenersSet = false;
|
||||
@@ -583,5 +583,4 @@ const extConfig = {
|
||||
getDislikeButton().querySelector(".button-renderer-text").innerText =
|
||||
mobileDislikes;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user