Fix Dislikes of Private Videos are "NaN"

will fix #230

List of changes:

* Adding a check to see if traceId exsits on response.
  This appears during error, so it will prevent setting dislike count to NaN.

* Changed a way to check if fields exist.
  Because the old way 0 likes or 0 dislikes are considered invalid.
This commit is contained in:
surrealegg committed 2021-12-06 22:28:45 +04:00
1 parent 3bca601e3d
commit a0e1a6dbab
2 files changed
+12 -12

No files matched your search

@@ -56,12 +56,12 @@ function isVideoNotDisliked() {
function getState() {
if (isVideoLiked()) {
return {current: LIKED_STATE, previous: storedData.previousState};
return { current: LIKED_STATE, previous: storedData.previousState };
}
if (isVideoDisliked()) {
return {current: DISLIKED_STATE, previous: storedData.previousState};
return { current: DISLIKED_STATE, previous: storedData.previousState };
}
return {current: NEUTRAL_STATE, previous: storedData.previousState};
return { current: NEUTRAL_STATE, previous: storedData.previousState };
}
//--- Sets The Likes And Dislikes Values ---//
@@ -84,7 +84,7 @@ function setState() {
cLog("response from youtube:");
cLog(JSON.stringify(response));
try {
if (response.likes && response.dislikes) {
if ("likes" in response && "dislikes" in response) {
const formattedDislike = numberFormat(response.dislikes);
setDislikes(formattedDislike);
storedData.dislikes = parseInt(response.dislikes);
@@ -107,7 +107,7 @@ function setState() {
function (response) {
cLog("response from api:");
cLog(JSON.stringify(response));
if (response != undefined && !statsSet) {
if (response != undefined && !("traceId" in response) && !statsSet) {
const formattedDislike = numberFormat(response.dislikes);
storedData.dislikes = response.dislikes;
// setLikes(response.likes);