mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Move generate userID to shared lib
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -27,7 +27,7 @@
|
|||||||
],
|
],
|
||||||
"license": "LGPL-3.0-or-later",
|
"license": "LGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": "^1.1.3",
|
"@ajayyy/maze-utils": "^1.1.4",
|
||||||
"content-scripts-register-polyfill": "^4.0.2",
|
"content-scripts-register-polyfill": "^4.0.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0"
|
"react-dom": "^18.2.0"
|
||||||
@@ -68,9 +68,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ajayyy/maze-utils": {
|
"node_modules/@ajayyy/maze-utils": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz",
|
||||||
"integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ==",
|
"integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "individual",
|
"type": "individual",
|
||||||
@@ -13420,9 +13420,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": {
|
"@ajayyy/maze-utils": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz",
|
||||||
"integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ=="
|
"integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ=="
|
||||||
},
|
},
|
||||||
"@ampproject/remapping": {
|
"@ampproject/remapping": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": "^1.1.3",
|
"@ajayyy/maze-utils": "^1.1.4",
|
||||||
"content-scripts-register-polyfill": "^4.0.2",
|
"content-scripts-register-polyfill": "^4.0.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0"
|
"react-dom": "^18.2.0"
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { Registration } from "./types";
|
|||||||
import registerContentScript from 'content-scripts-register-polyfill/ponyfill.js';
|
import registerContentScript from 'content-scripts-register-polyfill/ponyfill.js';
|
||||||
import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "@ajayyy/maze-utils/lib/background-request-proxy";
|
import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "@ajayyy/maze-utils/lib/background-request-proxy";
|
||||||
import { setupTabUpdates } from "@ajayyy/maze-utils/lib/tab-updates";
|
import { setupTabUpdates } from "@ajayyy/maze-utils/lib/tab-updates";
|
||||||
|
import { generateUserID } from "@ajayyy/maze-utils/lib/setup";
|
||||||
|
|
||||||
// Make the config public for debugging purposes
|
// Make the config public for debugging purposes
|
||||||
|
|
||||||
window.SB = Config;
|
window.SB = Config;
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
import { GenericUtils } from "./utils/genericUtils";
|
|
||||||
const utils = new Utils({
|
const utils = new Utils({
|
||||||
registerFirefoxContentScript,
|
registerFirefoxContentScript,
|
||||||
unregisterFirefoxContentScript
|
unregisterFirefoxContentScript
|
||||||
@@ -106,7 +106,7 @@ chrome.runtime.onInstalled.addListener(function () {
|
|||||||
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
|
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
|
||||||
|
|
||||||
//generate a userID
|
//generate a userID
|
||||||
const newUserID = GenericUtils.generateUserID();
|
const newUserID = generateUserID();
|
||||||
//save this UUID
|
//save this UUID
|
||||||
Config.config.userID = newUserID;
|
Config.config.userID = newUserID;
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ async function submitVote(type: number, UUID: string, category: string) {
|
|||||||
|
|
||||||
if (userID == undefined || userID === "undefined") {
|
if (userID == undefined || userID === "undefined") {
|
||||||
//generate one
|
//generate one
|
||||||
userID = GenericUtils.generateUserID();
|
userID = generateUserID();
|
||||||
Config.config.userID = userID;
|
Config.config.userID = userID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,27 +49,8 @@ function indexesOf<T>(array: T[], value: T): number[] {
|
|||||||
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
|
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateUserID(length = 36): string {
|
|
||||||
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
let result = "";
|
|
||||||
if (window.crypto && window.crypto.getRandomValues) {
|
|
||||||
const values = new Uint32Array(length);
|
|
||||||
window.crypto.getRandomValues(values);
|
|
||||||
for (let 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GenericUtils = {
|
export const GenericUtils = {
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
getLuminance,
|
getLuminance,
|
||||||
generateUserID,
|
|
||||||
indexesOf
|
indexesOf
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user