mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Made upvote system submit data to the server.
This commit is contained in:
@@ -41,6 +41,8 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
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) {
|
function submitTimes(videoID) {
|
||||||
//get the video times from storage
|
//get the video times from storage
|
||||||
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
||||||
@@ -130,6 +145,7 @@ function videoIDChange(currentVideoID) {
|
|||||||
function getUserID(callback) {
|
function getUserID(callback) {
|
||||||
if (userID != null) {
|
if (userID != null) {
|
||||||
callback(userID);
|
callback(userID);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if it is not cached yet, grab it from storage
|
//if it is not cached yet, grab it from storage
|
||||||
|
|||||||
18
content.js
18
content.js
@@ -264,10 +264,12 @@ function openSkipNotice(){
|
|||||||
let upvoteButton = document.createElement("img");
|
let upvoteButton = document.createElement("img");
|
||||||
upvoteButton.className = "sponsorSkipObject voteButton";
|
upvoteButton.className = "sponsorSkipObject voteButton";
|
||||||
upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
|
upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
|
||||||
|
upvoteButton.addEventListener("click", upvote);
|
||||||
|
|
||||||
let downvoteButton = document.createElement("img");
|
let downvoteButton = document.createElement("img");
|
||||||
downvoteButton.className = "sponsorSkipObject voteButton";
|
downvoteButton.className = "sponsorSkipObject voteButton";
|
||||||
downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
|
downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
|
||||||
|
downvoteButton.addEventListener("click", downvote);
|
||||||
|
|
||||||
//add thumbs up and down buttons to the container
|
//add thumbs up and down buttons to the container
|
||||||
voteButtonsContainer.appendChild(upvoteButton);
|
voteButtonsContainer.appendChild(upvoteButton);
|
||||||
@@ -311,6 +313,22 @@ function openSkipNotice(){
|
|||||||
referenceNode.prepend(noticeElement);
|
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
|
//Closes the notice that tells the user that a sponsor was just skipped
|
||||||
function closeSkipNotice(){
|
function closeSkipNotice(){
|
||||||
let notice = document.getElementById("sponsorSkipNotice");
|
let notice = document.getElementById("sponsorSkipNotice");
|
||||||
|
|||||||
Reference in New Issue
Block a user