mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-21 22:03:01 +01:00
Fixes after merges, prettier globally applied
This commit is contained in:
1 parent
58161ac123
commit
b0cb173830
47 files changed
+2183
-1942
No files matched your search
@@ -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,7 +35,7 @@ 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";
|
||||
@@ -101,29 +101,37 @@ function getDislikeButton() {
|
||||
let mutationObserver = new Object();
|
||||
|
||||
if (isShorts() && mutationObserver.exists !== true) {
|
||||
cLog('initializing mutation observer')
|
||||
cLog("initializing mutation observer");
|
||||
mutationObserver.options = {
|
||||
childList: false,
|
||||
attributes: true,
|
||||
subtree: false
|
||||
subtree: false,
|
||||
};
|
||||
mutationObserver.exists = true;
|
||||
mutationObserver.observer = new MutationObserver( function(mutationList, observer) {
|
||||
mutationList.forEach( (mutation) => {
|
||||
if (mutation.type === 'attributes' &&
|
||||
mutation.target.nodeName === 'TP-YT-PAPER-BUTTON' &&
|
||||
mutation.target.id === 'button') {
|
||||
cLog('Short thumb button status changed');
|
||||
if (mutation.target.getAttribute('aria-pressed') === 'true') {
|
||||
mutationObserver.observer = new MutationObserver(function (
|
||||
mutationList,
|
||||
observer
|
||||
) {
|
||||
mutationList.forEach((mutation) => {
|
||||
if (
|
||||
mutation.type === "attributes" &&
|
||||
mutation.target.nodeName === "TP-YT-PAPER-BUTTON" &&
|
||||
mutation.target.id === "button"
|
||||
) {
|
||||
cLog("Short thumb button status changed");
|
||||
if (mutation.target.getAttribute("aria-pressed") === "true") {
|
||||
mutation.target.style.color =
|
||||
(mutation.target.parentElement.parentElement.id === 'like-button') ?
|
||||
getColorFromTheme(true) : getColorFromTheme(false);
|
||||
mutation.target.parentElement.parentElement.id === "like-button"
|
||||
? getColorFromTheme(true)
|
||||
: getColorFromTheme(false);
|
||||
} else {
|
||||
mutation.target.style.color = 'unset';
|
||||
mutation.target.style.color = "unset";
|
||||
}
|
||||
return;
|
||||
}
|
||||
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||
cLog(
|
||||
"unexpected mutation observer event: " + mutation.target + mutation.type
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -270,25 +278,24 @@ function createRateBar(likes, dislikes) {
|
||||
var tooltipInnerHTML;
|
||||
switch (extConfig.tooltipPercentageMode) {
|
||||
case "dash_like":
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()} - ${likePercentage}%`
|
||||
break;
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()} - ${likePercentage}%`;
|
||||
break;
|
||||
case "dash_dislike":
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()} - ${dislikePercentage}%`
|
||||
break;
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()} - ${dislikePercentage}%`;
|
||||
break;
|
||||
case "both":
|
||||
tooltipInnerHTML = `${likePercentage}% / ${dislikePercentage}%`
|
||||
tooltipInnerHTML = `${likePercentage}% / ${dislikePercentage}%`;
|
||||
break;
|
||||
case "only_like":
|
||||
tooltipInnerHTML = `${likePercentage}%`
|
||||
tooltipInnerHTML = `${likePercentage}%`;
|
||||
break;
|
||||
case "only_dislike":
|
||||
tooltipInnerHTML = `${dislikePercentage}%`
|
||||
tooltipInnerHTML = `${dislikePercentage}%`;
|
||||
break;
|
||||
default:
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()}`
|
||||
tooltipInnerHTML = `${likes.toLocaleString()} / ${dislikes.toLocaleString()}`;
|
||||
}
|
||||
|
||||
|
||||
if (!rateBar && !isMobile) {
|
||||
let colorLikeStyle = "";
|
||||
let colorDislikeStyle = "";
|
||||
@@ -325,15 +332,16 @@ function createRateBar(likes, dislikes) {
|
||||
document.getElementById("return-youtube-dislike-bar").style.width =
|
||||
widthPercent + "%";
|
||||
|
||||
document.querySelector(
|
||||
"#ryd-dislike-tooltip > #tooltip"
|
||||
).innerHTML = tooltipInnerHTML;
|
||||
document.querySelector("#ryd-dislike-tooltip > #tooltip").innerHTML =
|
||||
tooltipInnerHTML;
|
||||
|
||||
if (extConfig.coloredBar) {
|
||||
document.getElementById("return-youtube-dislike-bar-container").style.backgroundColor =
|
||||
getColorFromTheme(false);
|
||||
document.getElementById("return-youtube-dislike-bar").style.backgroundColor =
|
||||
getColorFromTheme(true);
|
||||
document.getElementById(
|
||||
"return-youtube-dislike-bar-container"
|
||||
).style.backgroundColor = getColorFromTheme(false);
|
||||
document.getElementById(
|
||||
"return-youtube-dislike-bar"
|
||||
).style.backgroundColor = getColorFromTheme(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,17 +368,28 @@ function setState() {
|
||||
}
|
||||
createRateBar(likes, dislikes);
|
||||
if (extConfig.coloredThumbs === true) {
|
||||
if (isShorts()) { // for shorts, leave deactived buttons in default color
|
||||
let shortLikeButton = getLikeButton().querySelector('tp-yt-paper-button#button');
|
||||
let shortDislikeButton = getDislikeButton().querySelector('tp-yt-paper-button#button');
|
||||
if (shortLikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
if (isShorts()) {
|
||||
// for shorts, leave deactived buttons in default color
|
||||
let shortLikeButton = getLikeButton().querySelector(
|
||||
"tp-yt-paper-button#button"
|
||||
);
|
||||
let shortDislikeButton = getDislikeButton().querySelector(
|
||||
"tp-yt-paper-button#button"
|
||||
);
|
||||
if (shortLikeButton.getAttribute("aria-pressed") === "true") {
|
||||
shortLikeButton.style.color = getColorFromTheme(true);
|
||||
}
|
||||
if (shortDislikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
if (shortDislikeButton.getAttribute("aria-pressed") === "true") {
|
||||
shortDislikeButton.style.color = getColorFromTheme(false);
|
||||
}
|
||||
mutationObserver.observer.observe(shortLikeButton, mutationObserver.options);
|
||||
mutationObserver.observer.observe(shortDislikeButton, mutationObserver.options);
|
||||
mutationObserver.observer.observe(
|
||||
shortLikeButton,
|
||||
mutationObserver.options
|
||||
);
|
||||
mutationObserver.observer.observe(
|
||||
shortDislikeButton,
|
||||
mutationObserver.options
|
||||
);
|
||||
} else {
|
||||
getLikeButton().style.color = getColorFromTheme(true);
|
||||
getDislikeButton().style.color = getColorFromTheme(false);
|
||||
@@ -498,8 +517,10 @@ function getNumberFormatter(optionSelect) {
|
||||
?.getAttribute("href")
|
||||
)?.searchParams?.get("locale");
|
||||
} catch {
|
||||
cLog('Cannot find browser locale. Use en as default for number formatting.');
|
||||
userLocales = 'en';
|
||||
cLog(
|
||||
"Cannot find browser locale. Use en as default for number formatting."
|
||||
);
|
||||
userLocales = "en";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,13 +541,10 @@ function getNumberFormatter(optionSelect) {
|
||||
formatterCompactDisplay = "short";
|
||||
}
|
||||
|
||||
const formatter = Intl.NumberFormat(
|
||||
userLocales,
|
||||
{
|
||||
notation: formatterNotation,
|
||||
compactDisplay: formatterCompactDisplay,
|
||||
}
|
||||
);
|
||||
const formatter = Intl.NumberFormat(userLocales, {
|
||||
notation: formatterNotation,
|
||||
compactDisplay: formatterCompactDisplay,
|
||||
});
|
||||
return formatter;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user