diff --git a/background.js b/background.js index 904e46d9..7dcbd61d 100644 --- a/background.js +++ b/background.js @@ -130,34 +130,35 @@ function addSponsorTime(time, videoID, callback) { } function submitVote(type, UUID, callback) { - let userID = SB.config.userID; + let userID = SB.config.userID; - if (userID == undefined || userID === "undefined") { - //generate one - userID = generateUserID(); - SB.config.userID = userID; + if (userID == undefined || userID === "undefined") { + //generate one + userID = generateUserID(); + SB.config.userID = userID; + } + + //publish this vote + sendRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + callback({ + successType: 1 + }); + } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) { + //duplicate vote + callback({ + successType: 0, + statusCode: xmlhttp.status + }); + } else if (error) { + //error while connect + callback({ + successType: -1, + statusCode: xmlhttp.status + }); } - //publish this vote - sendRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - callback({ - successType: 1 - }); - } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) { - //duplicate vote - callback({ - successType: 0, - statusCode: xmlhttp.status - }); - } else if (error) { - //error while connect - callback({ - successType: -1, - statusCode: xmlhttp.status - }); - } - }) + }); } async function submitTimes(videoID, callback) {