diff options
Diffstat (limited to 'Extensions/UserScript/Return Youtube Dislike.user.js')
-rw-r--r-- | Extensions/UserScript/Return Youtube Dislike.user.js | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index b9ffa27..f3062fa 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -58,6 +58,9 @@ function isInViewport(element) { const height = innerHeight || document.documentElement.clientHeight; const width = innerWidth || document.documentElement.clientWidth; return ( + // When short (channel) is ignored, the element (like/dislike AND short itself) is + // hidden with a 0 DOMRect. In this case, consider it outside of Viewport + !(rect.top == 0 && rect.left == 0 && rect.bottom == 0 && rect.right == 0) && rect.top >= 0 && rect.left >= 0 && rect.bottom <= height && @@ -97,7 +100,8 @@ function getLikeButton() { function getLikeTextContainer() { return ( getLikeButton().querySelector("#text") ?? - getLikeButton().getElementsByTagName("yt-formatted-string")[0] + getLikeButton().getElementsByTagName("yt-formatted-string")[0] ?? + getLikeButton().querySelector("span[role='text']") ); } @@ -219,20 +223,29 @@ function setDislikes(dislikesCount) { mobileDislikes = dislikesCount; return; } + getDislikeTextContainer()?.removeAttribute('is-empty'); getDislikeTextContainer().innerText = dislikesCount; } 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. + try { + if (isShorts()) { + //Youtube Shorts don't work with this query. It's not necessary; 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. + return false; + } + let likeButton = getLikeButton() + .querySelector("yt-formatted-string#text") ?? + getLikeButton().querySelector("button"); + + let likesStr = likeButton.getAttribute("aria-label") + .replace(/\D/g, ""); + return likesStr.length > 0 ? parseInt(likesStr) : false; + } + catch { return false; } - let likesStr = getLikeButton() - .querySelector("yt-formatted-string#text") - .getAttribute("aria-label") - .replace(/\D/g, ""); - return likesStr.length > 0 ? parseInt(likesStr) : false; + } (typeof GM_addStyle != "undefined" |