diff options
author | Dmitrii Selivanov <selivano.d@gmail.com> | 2022-11-10 17:06:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 17:06:59 +0300 |
commit | aa10f30a704041ac4ddeb8e976701371f2ab0d8d (patch) | |
tree | b3e3293f4df3be5938c0df1851b9f55f36659292 /Extensions | |
parent | 033e1110236ac4f7c1dfbd71bba92d2a31edf5ec (diff) | |
parent | f1fe41e0776aa7164441da3389394ba07a94f00e (diff) |
Merge pull request #783 from hyperstown/re-format-numbers-fix
Fix reformat likes
Diffstat (limited to 'Extensions')
-rw-r--r-- | Extensions/UserScript/Return Youtube Dislike.user.js | 27 | ||||
-rw-r--r-- | Extensions/combined/manifest-chrome.json | 2 | ||||
-rw-r--r-- | Extensions/combined/manifest-firefox.json | 2 | ||||
-rw-r--r-- | Extensions/combined/src/buttons.js | 5 | ||||
-rw-r--r-- | Extensions/combined/src/state.js | 14 |
5 files changed, 32 insertions, 18 deletions
diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index 4dd048c..f3062fa 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -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" diff --git a/Extensions/combined/manifest-chrome.json b/Extensions/combined/manifest-chrome.json index 3e396a0..dddd2f6 100644 --- a/Extensions/combined/manifest-chrome.json +++ b/Extensions/combined/manifest-chrome.json @@ -2,7 +2,7 @@ "name": "__MSG_extensionName__", "description": "__MSG_extensionDesc__", "default_locale": "en", - "version": "3.0.0.5", + "version": "3.0.0.6", "manifest_version": 3, "background": { "service_worker": "ryd.background.js" diff --git a/Extensions/combined/manifest-firefox.json b/Extensions/combined/manifest-firefox.json index 07be68e..3ce248f 100644 --- a/Extensions/combined/manifest-firefox.json +++ b/Extensions/combined/manifest-firefox.json @@ -2,7 +2,7 @@ "name": "__MSG_extensionName__", "description": "__MSG_extensionDesc__", "default_locale": "en", - "version": "3.0.0.6", + "version": "3.0.0.7", "manifest_version": 2, "background": { "scripts": ["ryd.background.js"] diff --git a/Extensions/combined/src/buttons.js b/Extensions/combined/src/buttons.js index ab413a6..b78670c 100644 --- a/Extensions/combined/src/buttons.js +++ b/Extensions/combined/src/buttons.js @@ -24,7 +24,7 @@ function getButtons() { //--- If Menu Element Is Displayed: ---// if (document.getElementById("menu-container")?.offsetParent === null) { return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div"); - //--- If Menu Element Isnt Displayed: ---// + //--- If Menu Element Isn't Displayed: ---// } else { return document .getElementById("menu-container") @@ -42,7 +42,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']") ); } diff --git a/Extensions/combined/src/state.js b/Extensions/combined/src/state.js index 0876e10..444a203 100644 --- a/Extensions/combined/src/state.js +++ b/Extensions/combined/src/state.js @@ -133,10 +133,12 @@ function getState(storedData) { //--- Sets The Likes And Dislikes Values ---// function setLikes(likesCount) { + cLog(`SET likes ${likesCount}`) getLikeTextContainer().innerText = likesCount; } function setDislikes(dislikesCount) { + cLog(`SET dislikes ${dislikesCount}`) getDislikeTextContainer()?.removeAttribute('is-empty'); if (!isLikesDisabled()) { if (isMobile()) { @@ -161,13 +163,15 @@ function setDislikes(dislikesCount) { function getLikeCountFromButton() { try { if (isShorts()) { - //Youtube Shorts don't work with this query. It's not nessecary; we can skip it and still see the results. + //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 likesStr = getLikeButton() - .querySelector("yt-formatted-string#text") - .getAttribute("aria-label") + 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; } @@ -191,7 +195,7 @@ function processResponse(response, storedData) { createRateBar(storedData.likes, storedData.dislikes); if (extConfig.coloredThumbs === true) { if (isShorts()) { - // for shorts, leave deactived buttons in default color + // for shorts, leave deactivated buttons in default color let shortLikeButton = getLikeButton().querySelector( "tp-yt-paper-button#button" ); |