diff options
-rw-r--r-- | _locales/en/messages.json | 3 | ||||
-rw-r--r-- | background.js | 43 | ||||
-rw-r--r-- | content.js | 7 | ||||
-rw-r--r-- | manifest.json | 2 | ||||
-rw-r--r-- | popup.js | 9 |
5 files changed, 42 insertions, 22 deletions
diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 806abcf4..42256bb1 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -262,5 +262,8 @@ }, "keybindDescriptionComplete": { "message": "The keybind has been set to: " + }, + "0": { + "message": "Connection Timeout. Check your internet connection. If your internet is working, the server is probably overloaded or down." } } diff --git a/background.js b/background.js index 1f8aad75..7aaed64e 100644 --- a/background.js +++ b/background.js @@ -42,22 +42,24 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //add help page on install chrome.runtime.onInstalled.addListener(function (object) { - chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) { - const userID = result.userID; - - // If there is no userID, then it is the first install. - if (!userID){ - //open up the install page - chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))}); - - //generate a userID - const newUserID = generateUserID(); - //save this UUID - chrome.storage.sync.set({ - "userID": newUserID - }); - } - }); + setTimeout(function() { + chrome.storage.sync.get(["userID"], function(result) { + const userID = result.userID; + + // If there is no userID, then it is the first install. + if (!userID){ + //open up the install page + chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")}); + + //generate a userID + const newUserID = generateUserID(); + //save this UUID + chrome.storage.sync.set({ + "userID": newUserID + }); + } + }); + }, 1500); }); //gets the sponsor times from memory @@ -157,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) { @@ -175,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) { @@ -1041,8 +1041,11 @@ function sendSubmitMessage(){ document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png"); - if([400,429,409,502].includes(response.statusCode)) { - alert(chrome.i18n.getMessage(response.statusCode)); + if([400, 429, 409, 502, 0].includes(response.statusCode)) { + //treat them the same + if (response.statusCode == 503) response.statusCode = 502; + + alert(chrome.i18n.getMessage(response.statusCode + "")); } else { alert(chrome.i18n.getMessage("connectionError") + response.statusCode); } diff --git a/manifest.json b/manifest.json index 7ba848f2..6741f50e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_Name__", - "version": "1.1.9.3", + "version": "1.1.9.4", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [ @@ -811,8 +811,11 @@ function runThePopup() { } else { let errorMessage = ""; - if([400,429,409,502].includes(response.statusCode)) { - errorMessage = chrome.i18n.getMessage(response.statusCode); + if([400, 429, 409, 502, 0].includes(response.statusCode)) { + //treat them the same + if (response.statusCode == 503) response.statusCode = 502; + + errorMessage = chrome.i18n.getMessage(response.statusCode + ""); } else { errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode; } @@ -1109,8 +1112,10 @@ function runThePopup() { type: type, UUID: UUID }, function(response) { + console.log(response) if (response != undefined) { //see if it was a success or failure + console.log(response) if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) { //success (treat rate limits as a success) addVoteMessage(chrome.i18n.getMessage("voted"), UUID) |