Merge branch 'Anarios:main' into main

This commit is contained in:
Eryk Darnowski authored and GitHub committed 2022-05-03 14:08:15 +02:00
commit 94cc5734cb
21 files changed
+514 -478

No files matched your search

-27
View File
@@ -21,32 +21,6 @@ function sendVote(vote) {
}
}
function sendVideoIds() {
let links = Array.from(
document.getElementsByClassName(
"yt-simple-endpoint ytd-compact-video-renderer"
)
).concat(
Array.from(
document.getElementsByClassName("yt-simple-endpoint ytd-thumbnail")
)
);
// Also try mobile
if (links.length < 1)
links = Array.from(
document.querySelectorAll(
".large-media-item-metadata > a, a.large-media-item-thumbnail-container"
)
);
const ids = links
.filter((x) => x.href && x.href.indexOf("/watch?v=") > 0)
.map((x) => getVideoId(x.href));
getBrowser().runtime.sendMessage({
message: "send_links",
videoIds: ids,
});
}
function likeClicked() {
if (checkForSignInButton() === false) {
if (storedData.previousState === DISLIKED_STATE) {
@@ -166,7 +140,6 @@ function handleNumberDisplayReformatLikesChangeEvent(value) {
export {
sendVote,
sendVideoIds,
likeClicked,
dislikeClicked,
addLikeDislikeEventListener,
+44 -29
View File
@@ -7,7 +7,6 @@ import {
numberFormat,
getColorFromTheme,
} from "./utils";
import { sendVideoIds } from "./events";
import { localize } from "./utils";
//TODO: Do not duplicate here and in ryd.background.js
@@ -42,33 +41,40 @@ function isShorts() {
return location.pathname.startsWith("/shorts");
}
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') {
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') {
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
);
});
});
}
@@ -80,7 +86,9 @@ function isLikesDisabled() {
getButtons().children[0].querySelector(".button-renderer-text").innerText
);
}
return /^\D*$/.test(getButtons().children[0].querySelector("#text").innerText);
return /^\D*$/.test(
getButtons().children[0].querySelector("#text").innerText
);
}
function isVideoLiked() {
@@ -135,9 +143,8 @@ function setDislikes(dislikesCount) {
).innerText = localize("TextLikesDisabled");
return;
}
getButtons().children[1].querySelector("#text").innerText = localize(
"TextLikesDisabled"
);
getButtons().children[1].querySelector("#text").innerText =
localize("TextLikesDisabled");
}
}
@@ -167,17 +174,28 @@ function processResponse(response, storedData) {
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
createRateBar(storedData.likes, storedData.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);
@@ -227,9 +245,6 @@ async function setState(storedData) {
function setInitialState() {
setState(storedData);
setTimeout(() => {
sendVideoIds();
}, 1500);
}
function initExtConfig() {
@@ -351,5 +366,5 @@ export {
extConfig,
initExtConfig,
storedData,
isLikesDisabled
isLikesDisabled,
};
+8
View File
@@ -36,6 +36,14 @@ function localize(localeString) {
function getNumberFormatter(optionSelect) {
let formatterNotation;
let formatterCompactDisplay;
let userLocales;
try {
userLocales = new URL(
Array.from(document.querySelectorAll("head > link[rel='search']"))
?.find((n) => n?.getAttribute("href")?.includes("?locale="))
?.getAttribute("href")
)?.searchParams?.get("locale");
} catch {}
switch (optionSelect) {
case "compactLong":