|
@@ -16,8 +16,6 @@ const LIKED_STATE = "LIKED_STATE";
|
|
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
|
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
|
|
|
|
|
-const DISLIKES_DISABLED_TEXT = "DISLIKES DISABLED";
|
|
|
-
|
|
|
let extConfig = {
|
|
|
disableVoteSubmission: false,
|
|
|
coloredThumbs: false,
|
|
@@ -33,8 +31,6 @@ let storedData = {
|
|
|
previousState: NEUTRAL_STATE,
|
|
|
};
|
|
|
|
|
|
-let likesDisabledState = true;
|
|
|
-
|
|
|
function isMobile() {
|
|
|
return location.hostname == "m.youtube.com";
|
|
|
}
|
|
@@ -43,6 +39,16 @@ function isShorts() {
|
|
|
return location.pathname.startsWith("/shorts");
|
|
|
}
|
|
|
|
|
|
+function isLikesDisabled() {
|
|
|
+ // return true if the like button's text doesn't contain any number
|
|
|
+ if (isMobile()) {
|
|
|
+ return /^\D*$/.test(
|
|
|
+ getButtons().children[0].querySelector(".button-renderer-text").innerText
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return /^\D*$/.test(getButtons().children[0].querySelector("#text").innerText);
|
|
|
+}
|
|
|
+
|
|
|
function isVideoLiked() {
|
|
|
if (isMobile()) {
|
|
|
return (
|
|
@@ -79,7 +85,7 @@ function setLikes(likesCount) {
|
|
|
}
|
|
|
|
|
|
function setDislikes(dislikesCount) {
|
|
|
- if (!likesDisabledState) {
|
|
|
+ if (!isLikesDisabled()) {
|
|
|
if (isMobile()) {
|
|
|
getButtons().children[1].querySelector(
|
|
|
".button-renderer-text"
|
|
@@ -92,11 +98,12 @@ function setDislikes(dislikesCount) {
|
|
|
if (isMobile()) {
|
|
|
getButtons().children[1].querySelector(
|
|
|
".button-renderer-text"
|
|
|
- ).innerText = DISLIKES_DISABLED_TEXT;
|
|
|
+ ).innerText = localize("TextLikesDisabled");
|
|
|
return;
|
|
|
}
|
|
|
- getButtons().children[1].querySelector("#text").innerText =
|
|
|
- DISLIKES_DISABLED_TEXT;
|
|
|
+ getButtons().children[1].querySelector("#text").innerText = localize(
|
|
|
+ "TextLikesDisabled"
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -160,10 +167,6 @@ async function setState(storedData) {
|
|
|
.catch(displayError);
|
|
|
cLog("response from api:");
|
|
|
cLog(JSON.stringify(response));
|
|
|
- likesDisabledState =
|
|
|
- numberFormat(response.dislikes) == 0 &&
|
|
|
- numberFormat(response.likes) == 0 &&
|
|
|
- numberFormat(response.viewCount) == 0;
|
|
|
if (response !== undefined && !("traceId" in response) && !statsSet) {
|
|
|
processResponse(response, storedData);
|
|
|
}
|
|
@@ -262,5 +265,5 @@ export {
|
|
|
extConfig,
|
|
|
initExtConfig,
|
|
|
storedData,
|
|
|
- likesDisabledState,
|
|
|
+ isLikesDisabled
|
|
|
};
|