From f12b44762ec23745e6e75e8df9c68df96c4935e6 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 22 Aug 2019 16:08:16 -0400 Subject: [PATCH] Added new check to setup a proper userID if undefined while voting. --- background.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index afbe1644..64c7813c 100644 --- a/background.js +++ b/background.js @@ -56,7 +56,6 @@ chrome.runtime.onInstalled.addListener(function (object) { // TODO (shownInstallPage): remove this if statement, but leave contents if (!shownInstallPage){ //open up the install page - chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))}); } @@ -67,13 +66,10 @@ chrome.runtime.onInstalled.addListener(function (object) { } //generate a userID - const newUserID = generateUUID(); + const newUserID = generateUserID(); //save this UUID chrome.storage.sync.set({ - "userID": newUserID, - //the last video id loaded, to make sure it is a video id change - "sponsorVideoID": null, - "previousVideoID": null + "userID": newUserID }); } }); @@ -117,6 +113,14 @@ function submitVote(type, UUID, callback) { chrome.storage.sync.get(["userID"], function(result) { let userID = result.userID; + if (userID == undefined || userID === "undefined") { + //generate one + userID = generateUserID(); + chrome.storage.sync.set({ + "userID": userID + }); + } + //publish this vote sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { @@ -201,10 +205,9 @@ function sendRequestToServer(type, address, callback) { xmlhttp.send(); } -function generateUUID(length = 36) { +function generateUserID(length = 36) { let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let result = ""; - let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; if (window.crypto && window.crypto.getRandomValues) { values = new Uint32Array(length); window.crypto.getRandomValues(values);