diff options
author | Ajay Ramachandran <[email protected]> | 2019-07-15 19:13:09 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2019-07-15 19:13:09 -0400 |
commit | 987b7b036c004c0c42cc4be1c643b45d1c71f3b2 (patch) | |
tree | ad058f511d612d38ba1b16b25a808eca69a433cd | |
parent | 6cd01108f42c87bb9fae80936572ef2a7ef7659c (diff) | |
download | SponsorBlock-987b7b036c004c0c42cc4be1c643b45d1c71f3b2.tar.gz SponsorBlock-987b7b036c004c0c42cc4be1c643b45d1c71f3b2.zip |
Made upvote system submit data to the server.
-rw-r--r-- | background.js | 16 | ||||
-rw-r--r-- | content.js | 18 |
2 files changed, 34 insertions, 0 deletions
diff --git a/background.js b/background.js index 388d4cd3..c619bcbb 100644 --- a/background.js +++ b/background.js @@ -41,6 +41,8 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //this allows the callback to be called later return true; + } else if (request.message == "submitVote") { + submitVote(request.type, request.UUID) } }); @@ -79,6 +81,19 @@ function addSponsorTime(time) { }); } +function submitVote(type, UUID) { + let xmlhttp = new XMLHttpRequest(); + + getUserID(function(userID) { + //publish this vote + console.log(serverAddress + "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type); + xmlhttp.open('GET', serverAddress + "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, true); + + //submit this vote + xmlhttp.send(); + }) +} + function submitTimes(videoID) { //get the video times from storage let sponsorTimeKey = 'sponsorTimes' + videoID; @@ -130,6 +145,7 @@ function videoIDChange(currentVideoID) { function getUserID(callback) { if (userID != null) { callback(userID); + return; } //if it is not cached yet, grab it from storage @@ -264,10 +264,12 @@ function openSkipNotice(){ let upvoteButton = document.createElement("img"); upvoteButton.className = "sponsorSkipObject voteButton"; upvoteButton.src = chrome.extension.getURL("icons/upvote.png"); + upvoteButton.addEventListener("click", upvote); let downvoteButton = document.createElement("img"); downvoteButton.className = "sponsorSkipObject voteButton"; downvoteButton.src = chrome.extension.getURL("icons/downvote.png"); + downvoteButton.addEventListener("click", downvote); //add thumbs up and down buttons to the container voteButtonsContainer.appendChild(upvoteButton); @@ -311,6 +313,22 @@ function openSkipNotice(){ referenceNode.prepend(noticeElement); } +function upvote() { + vote(1); +} + +function downvote() { + vote(0); +} + +function vote(type) { + chrome.runtime.sendMessage({ + message: "submitVote", + type: type, + UUID: lastSponsorTimeSkippedUUID + }); +} + //Closes the notice that tells the user that a sponsor was just skipped function closeSkipNotice(){ let notice = document.getElementById("sponsorSkipNotice"); |