aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-11-23 12:49:19 -0500
committerGitHub <[email protected]>2019-11-23 12:49:19 -0500
commitff41251f17a5e189917969f95df351b2cca42432 (patch)
treed1b8be6d3d26498d5901d691cc95858e1cd18312
parent1a28f714a119c672fa094f5d1edcae4956c8f53f (diff)
parentc7c1cb79a8c51eb1fb9ca0cd189b7a3209d7cdb2 (diff)
downloadSponsorBlock-ff41251f17a5e189917969f95df351b2cca42432.tar.gz
SponsorBlock-ff41251f17a5e189917969f95df351b2cca42432.zip
Merge pull request #171 from ajayyy/experimental-ajay1.1.9.4
Fixed error message, prevented double counting contributions and delayed userID generation
-rw-r--r--_locales/en/messages.json3
-rw-r--r--background.js43
-rw-r--r--content.js7
-rw-r--r--manifest.json2
-rw-r--r--popup.js9
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) {
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/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": [
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)