Skip to content

Commit

Permalink
Made upvote system submit data to the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jul 15, 2019
1 parent 6cd0110 commit 987b7b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions background.js
Expand Up @@ -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)
}
});

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions content.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 987b7b0

Please sign in to comment.