mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-01 10:21:22 +01:00
1 parent
2e6ed5298b
commit
f752d02e51
1 file changed
+45
-2
@@ -42,6 +42,36 @@ function isShorts() {
|
|||||||
return location.pathname.startsWith("/shorts");
|
return location.pathname.startsWith("/shorts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mutationObserver = new Object();
|
||||||
|
|
||||||
|
if (isShorts() && mutationObserver.exists !== true) {
|
||||||
|
cLog('initializing mutation observer')
|
||||||
|
mutationObserver.options = {
|
||||||
|
childList: false,
|
||||||
|
attributes: true,
|
||||||
|
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') {
|
||||||
|
mutation.target.style.color =
|
||||||
|
(mutation.target.parentElement.parentElement.id === 'like-button') ?
|
||||||
|
getColorFromTheme(true) : getColorFromTheme(false);
|
||||||
|
} else {
|
||||||
|
mutation.target.style.color = 'unset';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function isVideoLiked() {
|
function isVideoLiked() {
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
return (
|
return (
|
||||||
@@ -119,8 +149,21 @@ function processResponse(response, storedData) {
|
|||||||
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
||||||
createRateBar(storedData.likes, storedData.dislikes);
|
createRateBar(storedData.likes, storedData.dislikes);
|
||||||
if (extConfig.coloredThumbs === true) {
|
if (extConfig.coloredThumbs === true) {
|
||||||
getLikeButton().style.color = getColorFromTheme(true);
|
if (isShorts()) { // for shorts, leave deactived buttons in default color
|
||||||
getDislikeButton().style.color = getColorFromTheme(false);
|
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') {
|
||||||
|
shortDislikeButton.style.color = getColorFromTheme(false);
|
||||||
|
}
|
||||||
|
mutationObserver.observer.observe(shortLikeButton, mutationObserver.options);
|
||||||
|
mutationObserver.observer.observe(shortDislikeButton, mutationObserver.options);
|
||||||
|
} else {
|
||||||
|
getLikeButton().style.color = getColorFromTheme(true);
|
||||||
|
getDislikeButton().style.color = getColorFromTheme(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user