mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 22:17:21 +03:00
Added new check to setup a proper userID if undefined while voting.
This commit is contained in:
@@ -56,7 +56,6 @@ chrome.runtime.onInstalled.addListener(function (object) {
|
|||||||
// TODO (shownInstallPage): remove this if statement, but leave contents
|
// TODO (shownInstallPage): remove this if statement, but leave contents
|
||||||
if (!shownInstallPage){
|
if (!shownInstallPage){
|
||||||
//open up the install page
|
//open up the install page
|
||||||
|
|
||||||
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
|
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
|
//generate a userID
|
||||||
const newUserID = generateUUID();
|
const newUserID = generateUserID();
|
||||||
//save this UUID
|
//save this UUID
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
"userID": newUserID,
|
"userID": newUserID
|
||||||
//the last video id loaded, to make sure it is a video id change
|
|
||||||
"sponsorVideoID": null,
|
|
||||||
"previousVideoID": null
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -117,6 +113,14 @@ function submitVote(type, UUID, callback) {
|
|||||||
chrome.storage.sync.get(["userID"], function(result) {
|
chrome.storage.sync.get(["userID"], function(result) {
|
||||||
let userID = result.userID;
|
let userID = result.userID;
|
||||||
|
|
||||||
|
if (userID == undefined || userID === "undefined") {
|
||||||
|
//generate one
|
||||||
|
userID = generateUserID();
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
"userID": userID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//publish this vote
|
//publish this vote
|
||||||
sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
|
sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
|
||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
@@ -201,10 +205,9 @@ function sendRequestToServer(type, address, callback) {
|
|||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateUUID(length = 36) {
|
function generateUserID(length = 36) {
|
||||||
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
let result = "";
|
let result = "";
|
||||||
let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
|
|
||||||
if (window.crypto && window.crypto.getRandomValues) {
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
values = new Uint32Array(length);
|
values = new Uint32Array(length);
|
||||||
window.crypto.getRandomValues(values);
|
window.crypto.getRandomValues(values);
|
||||||
|
|||||||
Reference in New Issue
Block a user