diff --git a/background.js b/background.js index 3961009b..ae1f7e45 100644 --- a/background.js +++ b/background.js @@ -215,22 +215,4 @@ function sendRequestToServer(type, address, callback) { //submit this request 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; - } -} +} \ No newline at end of file diff --git a/content.js b/content.js index c509e6cc..8547342f 100644 --- a/content.js +++ b/content.js @@ -1041,6 +1041,9 @@ function submitSponsorTimes() { //update sponsorTimes chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); + //update sponsorTimesSubmitting + sponsorTimesSubmitting = sponsorTimes; + let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes) + "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary"); if(!confirm(confirmMessage)) return; @@ -1060,8 +1063,6 @@ function sendSubmitMessage(){ let currentVideoID = sponsorVideoID; - let currentSponsorTimes = submitSponsorTimes; - chrome.runtime.sendMessage({ message: "submitTimes", videoID: currentVideoID @@ -1085,11 +1086,19 @@ function sendSubmitMessage(){ //clear the sponsor times let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar()); + chrome.storage.sync.set({[sponsorTimeKey]: []}); //add submissions to current sponsors list sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); + for (let i = 0; i < sponsorTimesSubmitting.length; i++) { + // Add some random IDs + UUIDs.push(generateUserID()); + } + + // Empty the submitting times sponsorTimesSubmitting = []; + + updatePreviewBar(); } else { //show that the upload failed document.getElementById("submitButton").style.animation = "unset"; diff --git a/utils.js b/utils.js index 379814cd..838769a2 100644 --- a/utils.js +++ b/utils.js @@ -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 *