Fixed new submissions getting added to the downloaded submissions.

This commit is contained in:
Ajay Ramachandran
2019-12-13 21:55:43 -05:00
parent b34e6076e4
commit a5baebab3f
3 changed files with 31 additions and 22 deletions

View File

@@ -216,21 +216,3 @@ function sendRequestToServer(type, address, callback) {
//submit this request //submit this request
xmlhttp.send(); xmlhttp.send();
} }
function generateUserID(length = 36) {
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
if (window.crypto && window.crypto.getRandomValues) {
values = new Uint32Array(length);
window.crypto.getRandomValues(values);
for (i = 0; i < length; i++) {
result += charset[values[i] % charset.length];
}
return result;
} else {
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
}

View File

@@ -1041,6 +1041,9 @@ function submitSponsorTimes() {
//update sponsorTimes //update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
//update sponsorTimesSubmitting
sponsorTimesSubmitting = sponsorTimes;
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes) let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary"); + "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
if(!confirm(confirmMessage)) return; if(!confirm(confirmMessage)) return;
@@ -1060,8 +1063,6 @@ function sendSubmitMessage(){
let currentVideoID = sponsorVideoID; let currentVideoID = sponsorVideoID;
let currentSponsorTimes = submitSponsorTimes;
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "submitTimes", message: "submitTimes",
videoID: currentVideoID videoID: currentVideoID
@@ -1085,11 +1086,19 @@ function sendSubmitMessage(){
//clear the sponsor times //clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar()); chrome.storage.sync.set({[sponsorTimeKey]: []});
//add submissions to current sponsors list //add submissions to current sponsors list
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
// Add some random IDs
UUIDs.push(generateUserID());
}
// Empty the submitting times
sponsorTimesSubmitting = []; sponsorTimesSubmitting = [];
updatePreviewBar();
} else { } else {
//show that the upload failed //show that the upload failed
document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitButton").style.animation = "unset";

View File

@@ -66,6 +66,24 @@ function localizeHtmlPage() {
} }
} }
function generateUserID(length = 36) {
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
if (window.crypto && window.crypto.getRandomValues) {
values = new Uint32Array(length);
window.crypto.getRandomValues(values);
for (i = 0; i < length; i++) {
result += charset[values[i] % charset.length];
}
return result;
} else {
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
}
/** /**
* Gets the error message in a nice string * Gets the error message in a nice string
* *