Merge pull request #171 from ajayyy/experimental-ajay

Fixed error message, prevented double counting contributions and delayed userID generation
This commit is contained in:
Ajay Ramachandran 2019-11-23 12:49:19 -05:00 committed by GitHub
commit ff41251f17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 20 deletions

View file

@ -262,5 +262,8 @@
}, },
"keybindDescriptionComplete": { "keybindDescriptionComplete": {
"message": "The keybind has been set to: " "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."
} }
} }

View file

@ -42,22 +42,24 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
//add help page on install //add help page on install
chrome.runtime.onInstalled.addListener(function (object) { chrome.runtime.onInstalled.addListener(function (object) {
chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) { setTimeout(function() {
const userID = result.userID; chrome.storage.sync.get(["userID"], function(result) {
const userID = result.userID;
// If there is no userID, then it is the first install. // If there is no userID, then it is the first install.
if (!userID){ if (!userID){
//open up the install page //open up the install page
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))}); chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")});
//generate a userID //generate a userID
const newUserID = generateUserID(); const newUserID = generateUserID();
//save this UUID //save this UUID
chrome.storage.sync.set({ chrome.storage.sync.set({
"userID": newUserID "userID": newUserID
}); });
} }
}); });
}, 1500);
}); });
//gets the sponsor times from memory //gets the sponsor times from memory
@ -157,6 +159,9 @@ function submitTimes(videoID, callback) {
//submit these times //submit these times
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
//to prevent it from happeneing twice
let increasedContributionAmount = false;
//submit the sponsorTime //submit the sponsorTime
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
+ "&userID=" + userID, function(xmlhttp, error) { + "&userID=" + userID, function(xmlhttp, error) {
@ -175,7 +180,11 @@ function submitTimes(videoID, callback) {
} }
//save the amount contributed //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) { } else if (error) {

View file

@ -1041,8 +1041,11 @@ function sendSubmitMessage(){
document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitButton").style.animation = "unset";
document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png"); document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
if([400,429,409,502].includes(response.statusCode)) { if([400, 429, 409, 502, 0].includes(response.statusCode)) {
alert(chrome.i18n.getMessage(response.statusCode)); //treat them the same
if (response.statusCode == 503) response.statusCode = 502;
alert(chrome.i18n.getMessage(response.statusCode + ""));
} else { } else {
alert(chrome.i18n.getMessage("connectionError") + response.statusCode); alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
} }

View file

@ -1,7 +1,7 @@
{ {
"name": "__MSG_fullName__", "name": "__MSG_fullName__",
"short_name": "__MSG_Name__", "short_name": "__MSG_Name__",
"version": "1.1.9.3", "version": "1.1.9.4",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_Description__", "description": "__MSG_Description__",
"content_scripts": [ "content_scripts": [

View file

@ -811,8 +811,11 @@ function runThePopup() {
} else { } else {
let errorMessage = ""; let errorMessage = "";
if([400,429,409,502].includes(response.statusCode)) { if([400, 429, 409, 502, 0].includes(response.statusCode)) {
errorMessage = chrome.i18n.getMessage(response.statusCode); //treat them the same
if (response.statusCode == 503) response.statusCode = 502;
errorMessage = chrome.i18n.getMessage(response.statusCode + "");
} else { } else {
errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode; errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode;
} }
@ -1109,8 +1112,10 @@ function runThePopup() {
type: type, type: type,
UUID: UUID UUID: UUID
}, function(response) { }, function(response) {
console.log(response)
if (response != undefined) { if (response != undefined) {
//see if it was a success or failure //see if it was a success or failure
console.log(response)
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) { if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
//success (treat rate limits as a success) //success (treat rate limits as a success)
addVoteMessage(chrome.i18n.getMessage("voted"), UUID) addVoteMessage(chrome.i18n.getMessage("voted"), UUID)