diff options
author | Dmitrii Selivanov <selivano.d@gmail.com> | 2022-07-20 01:06:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-20 01:06:45 +0300 |
commit | f4e5591f665a71c432bf067a111ccda4e6f6b1e6 (patch) | |
tree | e95327c60189fb6da1fb820daf076c5defeaf83b | |
parent | fe64c63f91c8e74f05a7a78d358e7dbccbeff67d (diff) | |
parent | 08a7ec17adaa169552224a003078c5c9caba12ef (diff) |
Merge pull request #594 from cyrildtm/fixLikeUpdated
Fix like numbers re-format
-rw-r--r-- | Extensions/UserScript/Return Youtube Dislike.user.js | 16 | ||||
-rw-r--r-- | Extensions/combined/popup.html | 2 | ||||
-rw-r--r-- | Extensions/combined/src/events.js | 13 | ||||
-rw-r--r-- | Extensions/combined/src/state.js | 4 |
4 files changed, 30 insertions, 5 deletions
diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js index 934b2d5..bbbbd45 100644 --- a/Extensions/UserScript/Return Youtube Dislike.user.js +++ b/Extensions/UserScript/Return Youtube Dislike.user.js @@ -204,10 +204,10 @@ 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. - return 0; + return false; } let likesStr = getLikeButton() - .querySelector("button") + .querySelector("yt-formatted-string#text") .getAttribute("aria-label") .replace(/\D/g, ""); return likesStr.length > 0 ? parseInt(likesStr) : false; @@ -399,6 +399,12 @@ function likeClicked() { createRateBar(likesvalue, dislikesvalue); previousState = 1; } + if (extConfig.numberDisplayReformatLikes === true) { + const nativeLikes = getLikeCountFromButton(); + if (nativeLikes !== false) { + setLikes(numberFormat(nativeLikes)); + } + } } } @@ -420,6 +426,12 @@ function dislikeClicked() { setDislikes(numberFormat(dislikesvalue)); createRateBar(likesvalue, dislikesvalue); previousState = 2; + if (extConfig.numberDisplayReformatLikes === true) { + const nativeLikes = getLikeCountFromButton(); + if (nativeLikes !== false) { + setLikes(numberFormat(nativeLikes)); + } + } } } } diff --git a/Extensions/combined/popup.html b/Extensions/combined/popup.html index 45c4ccd..3e9b9c0 100644 --- a/Extensions/combined/popup.html +++ b/Extensions/combined/popup.html @@ -108,7 +108,7 @@ <span class="switchLabel">Show rounded down numbers</span> </label> <br/> - <label class="switch" data-hover="Make likes and dislikes format consistent"> + <label class="switch" data-hover="Make likes and dislikes format consistent (does not work on Shorts)"> <input type="checkbox" id="number_reformat_likes"/> <span class="slider"/> <span class="switchLabel">Re-format like numbers</span> diff --git a/Extensions/combined/src/events.js b/Extensions/combined/src/events.js index 99c7d14..019f166 100644 --- a/Extensions/combined/src/events.js +++ b/Extensions/combined/src/events.js @@ -8,6 +8,7 @@ import { extConfig, storedData, setLikes, + getLikeCountFromButton, } from "./state"; import { createRateBar } from "./bar"; @@ -41,6 +42,12 @@ function likeClicked() { createRateBar(storedData.likes, storedData.dislikes); storedData.previousState = NEUTRAL_STATE; } + if (extConfig.numberDisplayReformatLikes === true) { + const nativeLikes = getLikeCountFromButton(); + if (nativeLikes !== false) { + setLikes(numberFormat(nativeLikes)); + } + } } } @@ -65,6 +72,12 @@ function dislikeClicked() { setDislikes(numberFormat(storedData.dislikes)); createRateBar(storedData.likes, storedData.dislikes); storedData.previousState = DISLIKED_STATE; + if (extConfig.numberDisplayReformatLikes === true) { + const nativeLikes = getLikeCountFromButton(); + if (nativeLikes !== false) { + setLikes(numberFormat(nativeLikes)); + } + } } } } diff --git a/Extensions/combined/src/state.js b/Extensions/combined/src/state.js index 34b15a1..52f68d4 100644 --- a/Extensions/combined/src/state.js +++ b/Extensions/combined/src/state.js @@ -153,10 +153,10 @@ 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. - return 0; + return false; } let likesStr = getLikeButton() - .querySelector("button") + .querySelector("yt-formatted-string#text") .getAttribute("aria-label") .replace(/\D/g, ""); return likesStr.length > 0 ? parseInt(likesStr) : false; |