diff --git a/src/background.ts b/src/background.ts index 1582327c..b204b64c 100644 --- a/src/background.ts +++ b/src/background.ts @@ -31,11 +31,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { case "openConfig": chrome.runtime.openOptionsPage(); return - case "submitTimes": - submitTimes(request.videoID, callback); - - //this allows the callback to be called later by the submitTimes function - return true; case "addSponsorTime": addSponsorTime(request.time, request.videoID, callback); @@ -182,61 +177,4 @@ function submitVote(type, UUID, callback) { } }); -} - -async function submitTimes(videoID: string, callback) { - //get the video times from storage - let sponsorTimes = Config.config.sponsorTimes.get(videoID); - let userID = Config.config.userID; - - if (sponsorTimes != undefined && sponsorTimes.length > 0) { - let durationResult = await new Promise((resolve, reject) => { - chrome.tabs.query({ - active: true, - currentWindow: true - }, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, { - message: "getVideoDuration" - }, (response) => resolve(response)); - }); - }); - - //check if a sponsor exceeds the duration of the video - for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i][1] > durationResult.duration) { - sponsorTimes[i][1] = durationResult.duration; - } - } - - //submit these times - for (let i = 0; i < sponsorTimes.length; i++) { - //to prevent it from happeneing twice - let increasedContributionAmount = false; - - //submit the sponsorTime - utils.sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] - + "&userID=" + userID, function(xmlhttp, error) { - if (xmlhttp.readyState == 4 && !error) { - callback({ - statusCode: xmlhttp.status, - responseText: xmlhttp.responseText - }); - - - - if (xmlhttp.status == 200) { - //save the amount contributed - if (!increasedContributionAmount) { - increasedContributionAmount = true; - Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimes.length; - } - } - } else if (error) { - callback({ - statusCode: -1 - }); - } - }); - } - } } \ No newline at end of file diff --git a/src/content.ts b/src/content.ts index 09fca172..6c1e3755 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1490,6 +1490,9 @@ async function sendSubmitMessage(){ sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); + // Increase contribution count + Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimesSubmitting.length; + // Empty the submitting times sponsorTimesSubmitting = [];