Skip to content

Commit

Permalink
Merge pull request #129 from ajayyy/experimental-ajay
Browse files Browse the repository at this point in the history
UserID undefined checks
  • Loading branch information
ajayyy authored Aug 22, 2019
2 parents 0ae3820 + d498c10 commit d1f1f92
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
19 changes: 11 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))});
}

Expand All @@ -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
});
}
});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,14 @@ function addPlayerControlsButton() {

let startSponsorButton = document.createElement("button");
startSponsorButton.id = "startSponsorButton";
startSponsorButton.draggable = false;
startSponsorButton.className = "ytp-button playerButton";
startSponsorButton.setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
startSponsorButton.addEventListener("click", startSponsorClicked);

let startSponsorImage = document.createElement("img");
startSponsorImage.id = "startSponsorImage";
startSponsorImage.draggable = false;
startSponsorImage.className = "playerButtonImage";
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");

Expand Down Expand Up @@ -675,12 +677,14 @@ function addInfoButton() {
//make a submit button
let infoButton = document.createElement("button");
infoButton.id = "infoButton";
infoButton.draggable = false;
infoButton.className = "ytp-button playerButton";
infoButton.setAttribute("title", "Open SponsorBlock Popup");
infoButton.addEventListener("click", openInfoMenu);

let infoImage = document.createElement("img");
infoImage.id = "infoButtonImage";
infoImage.draggable = false;
infoImage.className = "playerButtonImage";
infoImage.src = chrome.extension.getURL("icons/PlayerInfoIconSponsorBlocker256px.png");

Expand Down Expand Up @@ -709,6 +713,7 @@ function addDeleteButton() {
//make a submit button
let deleteButton = document.createElement("button");
deleteButton.id = "deleteButton";
deleteButton.draggable = false;
deleteButton.className = "ytp-button playerButton";
deleteButton.setAttribute("title", "Clear Sponsor Times");
deleteButton.addEventListener("click", clearSponsorTimes);
Expand All @@ -717,6 +722,7 @@ function addDeleteButton() {

let deleteImage = document.createElement("img");
deleteImage.id = "deleteButtonImage";
deleteImage.draggable = false;
deleteImage.className = "playerButtonImage";
deleteImage.src = chrome.extension.getURL("icons/PlayerDeleteIconSponsorBlocker256px.png");

Expand Down Expand Up @@ -745,6 +751,7 @@ function addSubmitButton() {
//make a submit button
let submitButton = document.createElement("button");
submitButton.id = "submitButton";
submitButton.draggable = false;
submitButton.className = "ytp-button playerButton";
submitButton.setAttribute("title", "Submit Sponsor Times");
submitButton.addEventListener("click", submitSponsorTimes);
Expand All @@ -753,6 +760,7 @@ function addSubmitButton() {

let submitImage = document.createElement("img");
submitImage.id = "submitButtonImage";
submitImage.draggable = false;
submitImage.className = "playerButtonImage";
submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");

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.2",
"version": "1.1.3",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
Expand Down

0 comments on commit d1f1f92

Please sign in to comment.