fix like reformat option to work with new design

This commit is contained in:
hyperstown committed 2022-10-18 00:39:21 +02:00
1 parent de1831f2c7
commit 87e922d41f
3 files changed
+30 -16

No files matched your search

@@ -100,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']")
);
}
@@ -227,16 +228,24 @@ function setDislikes(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"