aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-07-15 19:13:09 -0400
committerAjay Ramachandran <[email protected]>2019-07-15 19:13:09 -0400
commit987b7b036c004c0c42cc4be1c643b45d1c71f3b2 (patch)
treead058f511d612d38ba1b16b25a808eca69a433cd
parent6cd01108f42c87bb9fae80936572ef2a7ef7659c (diff)
downloadSponsorBlock-987b7b036c004c0c42cc4be1c643b45d1c71f3b2.tar.gz
SponsorBlock-987b7b036c004c0c42cc4be1c643b45d1c71f3b2.zip
Made upvote system submit data to the server.
-rw-r--r--background.js16
-rw-r--r--content.js18
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
diff --git a/content.js b/content.js
index f50a08b4..5cbc538d 100644
--- a/content.js
+++ b/content.js
@@ -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");