diff --git a/background.js b/background.js index e10e59a4..7aaed64e 100644 --- a/background.js +++ b/background.js @@ -159,6 +159,9 @@ function submitTimes(videoID, callback) { //submit these times for (let i = 0; i < sponsorTimes.length; i++) { + //to prevent it from happeneing twice + let increasedContributionAmount = false; + //submit the sponsorTime sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] + "&userID=" + userID, function(xmlhttp, error) { @@ -177,7 +180,11 @@ function submitTimes(videoID, callback) { } //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) {