Skip to content

Commit

Permalink
Merge pull request #171 from ajayyy/experimental-ajay
Browse files Browse the repository at this point in the history
Fixed error message, prevented double counting contributions and delayed userID generation
  • Loading branch information
ajayyy authored Nov 23, 2019
2 parents 1a28f71 + c7c1cb7 commit ff41251
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
43 changes: 26 additions & 17 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
9 changes: 7 additions & 2 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ff41251

Please sign in to comment.