Merge pull request #783 from hyperstown/re-format-numbers-fix

Fix reformat likes
This commit is contained in:
Dmitrii Selivanov authored and GitHub committed 2022-11-10 15:06:59 +01:00
commit aa10f30a70
5 files changed
+32 -18

No files matched your search

@@ -100,7 +100,8 @@ function getLikeButton() {
function getLikeTextContainer() { function getLikeTextContainer() {
return ( return (
getLikeButton().querySelector("#text") ?? 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() { function getLikeCountFromButton() {
if (isShorts()) { try {
//Youtube Shorts don't work with this query. It's not nessecary; we can skip it and still see the results. if (isShorts()) {
//It should be possible to fix this function, but it's not critical to showing the dislike count. //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; 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" (typeof GM_addStyle != "undefined"
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"description": "__MSG_extensionDesc__", "description": "__MSG_extensionDesc__",
"default_locale": "en", "default_locale": "en",
"version": "3.0.0.5", "version": "3.0.0.6",
"manifest_version": 3, "manifest_version": 3,
"background": { "background": {
"service_worker": "ryd.background.js" "service_worker": "ryd.background.js"
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"description": "__MSG_extensionDesc__", "description": "__MSG_extensionDesc__",
"default_locale": "en", "default_locale": "en",
"version": "3.0.0.6", "version": "3.0.0.7",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": ["ryd.background.js"] "scripts": ["ryd.background.js"]
+3 -2
View File
@@ -24,7 +24,7 @@ function getButtons() {
//--- If Menu Element Is Displayed: ---// //--- If Menu Element Is Displayed: ---//
if (document.getElementById("menu-container")?.offsetParent === null) { if (document.getElementById("menu-container")?.offsetParent === null) {
return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div"); return document.querySelector("ytd-menu-renderer.ytd-watch-metadata > div");
//--- If Menu Element Isnt Displayed: ---// //--- If Menu Element Isn't Displayed: ---//
} else { } else {
return document return document
.getElementById("menu-container") .getElementById("menu-container")
@@ -42,7 +42,8 @@ function getLikeButton() {
function getLikeTextContainer() { function getLikeTextContainer() {
return ( return (
getLikeButton().querySelector("#text") ?? getLikeButton().querySelector("#text") ??
getLikeButton().getElementsByTagName("yt-formatted-string")[0] getLikeButton().getElementsByTagName("yt-formatted-string")[0] ??
getLikeButton().querySelector("span[role='text']")
); );
} }
+9 -5
View File
@@ -133,10 +133,12 @@ function getState(storedData) {
//--- Sets The Likes And Dislikes Values ---// //--- Sets The Likes And Dislikes Values ---//
function setLikes(likesCount) { function setLikes(likesCount) {
cLog(`SET likes ${likesCount}`)
getLikeTextContainer().innerText = likesCount; getLikeTextContainer().innerText = likesCount;
} }
function setDislikes(dislikesCount) { function setDislikes(dislikesCount) {
cLog(`SET dislikes ${dislikesCount}`)
getDislikeTextContainer()?.removeAttribute('is-empty'); getDislikeTextContainer()?.removeAttribute('is-empty');
if (!isLikesDisabled()) { if (!isLikesDisabled()) {
if (isMobile()) { if (isMobile()) {
@@ -161,13 +163,15 @@ function setDislikes(dislikesCount) {
function getLikeCountFromButton() { function getLikeCountFromButton() {
try { try {
if (isShorts()) { 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. //It should be possible to fix this function, but it's not critical to showing the dislike count.
return false; return false;
} }
let likesStr = getLikeButton() let likeButton = getLikeButton()
.querySelector("yt-formatted-string#text") .querySelector("yt-formatted-string#text") ??
.getAttribute("aria-label") getLikeButton().querySelector("button");
let likesStr = likeButton.getAttribute("aria-label")
.replace(/\D/g, ""); .replace(/\D/g, "");
return likesStr.length > 0 ? parseInt(likesStr) : false; return likesStr.length > 0 ? parseInt(likesStr) : false;
} }
@@ -191,7 +195,7 @@ function processResponse(response, storedData) {
createRateBar(storedData.likes, storedData.dislikes); createRateBar(storedData.likes, storedData.dislikes);
if (extConfig.coloredThumbs === true) { if (extConfig.coloredThumbs === true) {
if (isShorts()) { if (isShorts()) {
// for shorts, leave deactived buttons in default color // for shorts, leave deactivated buttons in default color
let shortLikeButton = getLikeButton().querySelector( let shortLikeButton = getLikeButton().querySelector(
"tp-yt-paper-button#button" "tp-yt-paper-button#button"
); );