Prevented contributions from counting twice.

This commit is contained in:
Ajay Ramachandran
2019-11-23 12:47:00 -05:00
parent dfad1a5636
commit fc155ccdfa

View File

@@ -159,6 +159,9 @@ function submitTimes(videoID, callback) {
//submit these times //submit these times
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
//to prevent it from happeneing twice
let increasedContributionAmount = false;
//submit the sponsorTime //submit the sponsorTime
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
+ "&userID=" + userID, function(xmlhttp, error) { + "&userID=" + userID, function(xmlhttp, error) {
@@ -177,7 +180,11 @@ function submitTimes(videoID, callback) {
} }
//save the amount contributed //save the amount contributed
chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length}); if (!increasedContributionAmount) {
increasedContributionAmount = true;
chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length});
}
}); });
} }
} else if (error) { } else if (error) {