diff options
-rw-r--r-- | Extensions/firefox/return-youtube-dislike.script.js | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Extensions/firefox/return-youtube-dislike.script.js b/Extensions/firefox/return-youtube-dislike.script.js index 293388b..a00ed18 100644 --- a/Extensions/firefox/return-youtube-dislike.script.js +++ b/Extensions/firefox/return-youtube-dislike.script.js @@ -8,8 +8,11 @@ function cLog(message, writer) { } 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: ---// } else { return document .getElementById("menu-container") @@ -51,14 +54,22 @@ function getState() { return "neutral"; } +//--- Sets The Likes And Dislikes Values ---// function setLikes(likesCount) { getButtons().children[0].querySelector("#text").innerText = likesCount; } - function setDislikes(dislikesCount) { getButtons().children[1].querySelector("#text").innerText = dislikesCount; } +//--- Gets Current Dislike Value From Local Device ---// +function getDislikes() { + let dislikes = getButtons().children[1].querySelector("#text").innerText; + dislikes = parseInt(dislikes); + return dislikes; +} + + function setState() { let statsSet = false; browser.runtime.sendMessage( @@ -106,12 +117,21 @@ function setState() { } function likeClicked() { - // console.log("like" + getState()); + console.log("Dislike State:",getState()); // setState(); } function dislikeClicked() { - // console.log("dislike" + getState()); + let state = getState(); + + console.log("Dislike State:",state); + + if (state == 'disliked') { + setDislikes(getDislikes() + 1) + } else if (state == 'neutral') { + setDislikes(getDislikes() + -1) + } + // setState(); } |