mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-26 16:23:00 +01:00
Prettier applied to whole project, prettier added to pre-commit hook
This commit is contained in:
1 parent
47517ce0bd
commit
b133adeecb
59 files changed
+912
-819
No files matched your search
@@ -14,10 +14,8 @@ import {
|
||||
getColorFromTheme,
|
||||
querySelector,
|
||||
localize,
|
||||
createObserver
|
||||
} from './utils';
|
||||
import { createStarRating } from "./starRating";
|
||||
import { dislikeClicked } from './events';
|
||||
createObserver,
|
||||
} from "./utils";
|
||||
|
||||
//TODO: Do not duplicate here and in ryd.background.js
|
||||
const apiUrl = "https://returnyoutubedislikeapi.com";
|
||||
@@ -50,17 +48,17 @@ let extConfig = {
|
||||
likeButton: {
|
||||
segmented: [],
|
||||
segmentedGetButtons: [],
|
||||
notSegmented: []
|
||||
notSegmented: [],
|
||||
},
|
||||
dislikeButton: {
|
||||
segmented: [],
|
||||
segmentedGetButtons: [],
|
||||
notSegmented: []
|
||||
}
|
||||
notSegmented: [],
|
||||
},
|
||||
},
|
||||
menuContainer: [],
|
||||
roundedDesign: [],
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let storedData = {
|
||||
@@ -89,38 +87,43 @@ let shortsObserver = null;
|
||||
|
||||
if (isShorts() && !shortsObserver) {
|
||||
cLog("Initializing shorts mutation observer");
|
||||
shortsObserver = createObserver({
|
||||
attributes: true
|
||||
}, (mutationList) => {
|
||||
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);
|
||||
} else {
|
||||
mutation.target.style.color = "unset";
|
||||
shortsObserver = createObserver(
|
||||
{
|
||||
attributes: true,
|
||||
},
|
||||
(mutationList) => {
|
||||
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);
|
||||
} else {
|
||||
mutation.target.style.color = "unset";
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
cLog(
|
||||
"Unexpected mutation observer event: " + mutation.target + mutation.type
|
||||
);
|
||||
});
|
||||
});
|
||||
cLog(
|
||||
"Unexpected mutation observer event: " +
|
||||
mutation.target +
|
||||
mutation.type,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function isLikesDisabled() {
|
||||
// return true if the like button's text doesn't contain any number
|
||||
if (isMobile()) {
|
||||
return /^\D*$/.test(
|
||||
getButtons().children[0].querySelector(".button-renderer-text").innerText
|
||||
getButtons().children[0].querySelector(".button-renderer-text").innerText,
|
||||
);
|
||||
}
|
||||
return /^\D*$/.test(getLikeTextContainer().innerText);
|
||||
@@ -129,19 +132,29 @@ function isLikesDisabled() {
|
||||
function isVideoLiked() {
|
||||
if (isMobile()) {
|
||||
return (
|
||||
getLikeButton().querySelector("button").getAttribute("aria-label") === "true"
|
||||
getLikeButton().querySelector("button").getAttribute("aria-label") ===
|
||||
"true"
|
||||
);
|
||||
}
|
||||
return getLikeButton().classList.contains("style-default-active") || getLikeButton().querySelector('button')?.getAttribute('aria-pressed') === 'true';
|
||||
return (
|
||||
getLikeButton().classList.contains("style-default-active") ||
|
||||
getLikeButton().querySelector("button")?.getAttribute("aria-pressed") ===
|
||||
"true"
|
||||
);
|
||||
}
|
||||
|
||||
function isVideoDisliked() {
|
||||
if (isMobile()) {
|
||||
return (
|
||||
getDislikeButton().querySelector("button").getAttribute("aria-label") === "true"
|
||||
getDislikeButton().querySelector("button").getAttribute("aria-label") ===
|
||||
"true"
|
||||
);
|
||||
}
|
||||
return getDislikeButton().classList.contains("style-default-active") || getDislikeButton().querySelector('button')?.getAttribute('aria-pressed') === 'true';
|
||||
return (
|
||||
getDislikeButton().classList.contains("style-default-active") ||
|
||||
getDislikeButton().querySelector("button")?.getAttribute("aria-pressed") ===
|
||||
"true"
|
||||
);
|
||||
}
|
||||
|
||||
function getState(storedData) {
|
||||
@@ -156,27 +169,26 @@ function getState(storedData) {
|
||||
|
||||
//--- Sets The Likes And Dislikes Values ---//
|
||||
function setLikes(likesCount) {
|
||||
cLog(`SET likes ${likesCount}`)
|
||||
cLog(`SET likes ${likesCount}`);
|
||||
getLikeTextContainer().innerText = likesCount;
|
||||
}
|
||||
|
||||
function setDislikes(dislikesCount) {
|
||||
cLog(`SET dislikes ${dislikesCount}`)
|
||||
cLog(`SET dislikes ${dislikesCount}`);
|
||||
getDislikeTextContainer()?.removeAttribute("is-empty");
|
||||
if (!isLikesDisabled()) {
|
||||
if (isMobile()) {
|
||||
getButtons().children[1].querySelector(
|
||||
".button-renderer-text"
|
||||
".button-renderer-text",
|
||||
).innerText = dislikesCount;
|
||||
return;
|
||||
}
|
||||
getDislikeTextContainer().innerText = dislikesCount;
|
||||
|
||||
} else {
|
||||
cLog("likes count disabled by creator");
|
||||
if (isMobile()) {
|
||||
getButtons().children[1].querySelector(
|
||||
".button-renderer-text"
|
||||
".button-renderer-text",
|
||||
).innerText = localize("TextLikesDisabled");
|
||||
return;
|
||||
}
|
||||
@@ -192,12 +204,11 @@ function getLikeCountFromButton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let likeButton = getLikeButton()
|
||||
.querySelector("yt-formatted-string#text") ??
|
||||
getLikeButton().querySelector("button");
|
||||
let likeButton =
|
||||
getLikeButton().querySelector("yt-formatted-string#text") ??
|
||||
getLikeButton().querySelector("button");
|
||||
|
||||
let likesStr = likeButton.getAttribute("aria-label")
|
||||
.replace(/\D/g, "");
|
||||
let likesStr = likeButton.getAttribute("aria-label").replace(/\D/g, "");
|
||||
return likesStr.length > 0 ? parseInt(likesStr) : false;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -220,10 +231,10 @@ function processResponse(response, storedData) {
|
||||
if (isShorts()) {
|
||||
// for shorts, leave deactivated buttons in default color
|
||||
let shortLikeButton = getLikeButton().querySelector(
|
||||
"tp-yt-paper-button#button"
|
||||
"tp-yt-paper-button#button",
|
||||
);
|
||||
let shortDislikeButton = getDislikeButton().querySelector(
|
||||
"tp-yt-paper-button#button"
|
||||
"tp-yt-paper-button#button",
|
||||
);
|
||||
if (shortLikeButton.getAttribute("aria-pressed") === "true") {
|
||||
shortLikeButton.style.color = getColorFromTheme(true);
|
||||
@@ -244,17 +255,15 @@ function processResponse(response, storedData) {
|
||||
|
||||
// Tells the user if the API is down
|
||||
function displayError(error) {
|
||||
getDislikeTextContainer().innerText = localize(
|
||||
"textTempUnavailable"
|
||||
);
|
||||
getDislikeTextContainer().innerText = localize("textTempUnavailable");
|
||||
}
|
||||
|
||||
async function setState(storedData) {
|
||||
storedData.previousState = isVideoDisliked()
|
||||
? DISLIKED_STATE
|
||||
: isVideoLiked()
|
||||
? LIKED_STATE
|
||||
: NEUTRAL_STATE;
|
||||
? LIKED_STATE
|
||||
: NEUTRAL_STATE;
|
||||
let statsSet = false;
|
||||
cLog("Video is loaded. Adding buttons...");
|
||||
|
||||
@@ -268,7 +277,7 @@ async function setState(storedData) {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
.then((response) => {
|
||||
if (!response.ok) displayError(response.error);
|
||||
@@ -283,11 +292,11 @@ async function setState(storedData) {
|
||||
}
|
||||
}
|
||||
|
||||
async function setInitialState () {
|
||||
async function setInitialState() {
|
||||
await setState(storedData);
|
||||
}
|
||||
|
||||
async function initExtConfig () {
|
||||
async function initExtConfig() {
|
||||
initializeDisableVoteSubmission();
|
||||
initializeColoredThumbs();
|
||||
initializeColoredBar();
|
||||
@@ -299,16 +308,18 @@ async function initExtConfig () {
|
||||
await initializeSelectors();
|
||||
}
|
||||
|
||||
async function initializeSelectors () {
|
||||
console.log("initializing selectors")
|
||||
async function initializeSelectors() {
|
||||
console.log("initializing selectors");
|
||||
let result = await fetch(`${apiUrl}/configs/selectors`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
}
|
||||
}).then((response) => response.json()).catch((error) => {});
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.catch((error) => {});
|
||||
extConfig.selectors = result ?? extConfig.selectors;
|
||||
console.log(result)
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
function initializeDisableVoteSubmission() {
|
||||
|
||||
Reference in new issue
Block a user