diff options
author | Ajay <[email protected]> | 2023-02-18 02:54:42 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2023-02-18 02:54:42 -0500 |
commit | 4ca6a331f1bfb08447fe2bc7f94cf6ed599b2d32 (patch) | |
tree | 56fb9f0bf85116f1e75c031c4aa16b2090d3f651 | |
parent | 1d05c2b3dfc15619a02f0d9333be8051cde60acb (diff) | |
download | SponsorBlock-4ca6a331f1bfb08447fe2bc7f94cf6ed599b2d32.tar.gz SponsorBlock-4ca6a331f1bfb08447fe2bc7f94cf6ed599b2d32.zip |
Move generate userID to shared lib
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/background.ts | 6 | ||||
-rw-r--r-- | src/utils/genericUtils.ts | 19 |
4 files changed, 11 insertions, 30 deletions
diff --git a/package-lock.json b/package-lock.json index c9ea5dcf..f9483003 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ ], "license": "LGPL-3.0-or-later", "dependencies": { - "@ajayyy/maze-utils": "^1.1.3", + "@ajayyy/maze-utils": "^1.1.4", "content-scripts-register-polyfill": "^4.0.2", "react": "^18.2.0", "react-dom": "^18.2.0" @@ -68,9 +68,9 @@ } }, "node_modules/@ajayyy/maze-utils": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz", - "integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz", + "integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ==", "funding": [ { "type": "individual", @@ -13420,9 +13420,9 @@ }, "dependencies": { "@ajayyy/maze-utils": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz", - "integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.4.tgz", + "integrity": "sha512-6sS6Q7v5w2dwr6rrH7GinkPlbN5rx8gr5QkBSEpNux6jbRSb3/25t4WQCYn9nSeEzTSsBq2U6wjlscqa/RWKYQ==" }, "@ampproject/remapping": { "version": "2.2.0", diff --git a/package.json b/package.json index 406a213e..1da498bb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "background.js", "dependencies": { - "@ajayyy/maze-utils": "^1.1.3", + "@ajayyy/maze-utils": "^1.1.4", "content-scripts-register-polyfill": "^4.0.2", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/src/background.ts b/src/background.ts index d04f51d3..f79cfcaf 100644 --- a/src/background.ts +++ b/src/background.ts @@ -5,13 +5,13 @@ import { Registration } from "./types"; import registerContentScript from 'content-scripts-register-polyfill/ponyfill.js'; import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "@ajayyy/maze-utils/lib/background-request-proxy"; import { setupTabUpdates } from "@ajayyy/maze-utils/lib/tab-updates"; +import { generateUserID } from "@ajayyy/maze-utils/lib/setup"; // Make the config public for debugging purposes window.SB = Config; import Utils from "./utils"; -import { GenericUtils } from "./utils/genericUtils"; const utils = new Utils({ registerFirefoxContentScript, unregisterFirefoxContentScript @@ -106,7 +106,7 @@ chrome.runtime.onInstalled.addListener(function () { chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")}); //generate a userID - const newUserID = GenericUtils.generateUserID(); + const newUserID = generateUserID(); //save this UUID Config.config.userID = newUserID; @@ -157,7 +157,7 @@ async function submitVote(type: number, UUID: string, category: string) { if (userID == undefined || userID === "undefined") { //generate one - userID = GenericUtils.generateUserID(); + userID = generateUserID(); Config.config.userID = userID; } diff --git a/src/utils/genericUtils.ts b/src/utils/genericUtils.ts index 78c481e3..7902b6b6 100644 --- a/src/utils/genericUtils.ts +++ b/src/utils/genericUtils.ts @@ -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); } -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 = { getErrorMessage, getLuminance, - generateUserID, indexesOf }
\ No newline at end of file |