From 6790952f860eab70bff38be9d300365b08423818 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 23 Nov 2019 12:26:24 -0500 Subject: [PATCH 1/4] Fixed error messages not working. Added message for error 503 and 0. --- _locales/en/messages.json | 3 +++ content.js | 7 +++++-- popup.js | 9 +++++++-- 3 files changed, 15 insertions(+), 4 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/content.js b/content.js index 276c93c9..ec55863b 100644 --- a/content.js +++ b/content.js @@ -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/popup.js b/popup.js index 5dfaadda..337dd020 100644 --- a/popup.js +++ b/popup.js @@ -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) From dfad1a5636dac4063d5ec6fbe40db9a00106a18c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 23 Nov 2019 12:44:38 -0500 Subject: [PATCH 2/4] Added delayed startup after install. --- background.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/background.js b/background.js index 1f8aad75..e10e59a4 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; + 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/"+chrome.i18n.getMessage("helpPage"))}); + // 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 - }); - } - }); + //generate a userID + const newUserID = generateUserID(); + //save this UUID + chrome.storage.sync.set({ + "userID": newUserID + }); + } + }); + }, 1500); }); //gets the sponsor times from memory From fc155ccdfaff532c50d0e6503245b9b1038bec5f Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 23 Nov 2019 12:47:00 -0500 Subject: [PATCH 3/4] Prevented contributions from counting twice. --- background.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) { From c7c1cb79a8c51eb1fb9ca0cd189b7a3209d7cdb2 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 23 Nov 2019 12:48:10 -0500 Subject: [PATCH 4/4] Increased version number. --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": [