aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--package-lock.json14
-rw-r--r--package.json2
-rw-r--r--src/config.ts3
-rw-r--r--src/content.ts8
-rw-r--r--src/options.ts3
-rw-r--r--src/popup.ts5
-rw-r--r--src/types.ts2
-rw-r--r--src/utils.ts21
-rw-r--r--src/utils/licenseKey.ts3
-rw-r--r--src/utils/warnings.ts5
10 files changed, 28 insertions, 38 deletions
diff --git a/package-lock.json b/package-lock.json
index 2e3613fc..c9ea5dcf 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.2",
+ "@ajayyy/maze-utils": "^1.1.3",
"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.2",
- "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.2.tgz",
- "integrity": "sha512-hz8+ONJMnkX3q1XHzN2JEmmg4otsEr88SbnH2Oq35WfWuaGnjsm5VVowEZeAoEd/7ELxD+Mhk+rGZLMzSHXbqQ==",
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
+ "integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ==",
"funding": [
{
"type": "individual",
@@ -13420,9 +13420,9 @@
},
"dependencies": {
"@ajayyy/maze-utils": {
- "version": "1.1.2",
- "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.2.tgz",
- "integrity": "sha512-hz8+ONJMnkX3q1XHzN2JEmmg4otsEr88SbnH2Oq35WfWuaGnjsm5VVowEZeAoEd/7ELxD+Mhk+rGZLMzSHXbqQ=="
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.3.tgz",
+ "integrity": "sha512-3JPPTsmW4G928M4vM6hSo5eU7FZoVLBRuhnuS4Fzi3/3miEgSwV0g1nbwWy4wJrKeB19GSaCGVjLxsGTWsgyrQ=="
},
"@ampproject/remapping": {
"version": "2.2.0",
diff --git a/package.json b/package.json
index 2c5e666b..406a213e 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"description": "",
"main": "background.js",
"dependencies": {
- "@ajayyy/maze-utils": "^1.1.2",
+ "@ajayyy/maze-utils": "^1.1.3",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
diff --git a/src/config.ts b/src/config.ts
index d57b6499..e04448e5 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1,8 +1,9 @@
import * as CompileConfig from "../config.json";
import * as invidiousList from "../ci/invidiouslist.json";
-import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, Keybind, HashedValue, VideoID, SponsorHideType } from "./types";
+import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, Keybind, VideoID, SponsorHideType } from "./types";
import { isSafari, keybindEquals } from "./utils/configUtils";
import { ProtoConfig } from "@ajayyy/maze-utils/lib/config";
+import { HashedValue } from "@ajayyy/maze-utils/lib/hash";
export interface Permission {
canSubmit: boolean;
diff --git a/src/content.ts b/src/content.ts
index f33ae093..5798d3ff 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -6,7 +6,6 @@ import {
ChannelIDInfo,
ChannelIDStatus,
ContentContainer,
- HashedValue,
Keybind,
ScheduledTime,
SegmentUUID,
@@ -42,6 +41,7 @@ import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
import { setupVideoMutationListener, getChannelIDInfo, getVideo, refreshVideoAttachments, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube } from "@ajayyy/maze-utils/lib/video";
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
import { findValidElement } from "@ajayyy/maze-utils/lib/dom"
+import { getHash, HashedValue } from "@ajayyy/maze-utils/lib/hash";
const utils = new Utils();
@@ -977,7 +977,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
const hashParams = getHashParams();
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
- const hashPrefix = (await utils.getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
+ const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
categories,
actionTypes: getEnabledActionTypes(showChapterMessage),
@@ -1060,7 +1060,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
const downvotedData = Config.local.downvotedSegments[hashPrefix];
if (downvotedData) {
for (const segment of sponsorTimes) {
- const hashedUUID = await utils.getHash(segment.UUID, 1);
+ const hashedUUID = await getHash(segment.UUID, 1);
const segmentDownvoteData = downvotedData.segments.find((downvote) => downvote.uuid === hashedUUID);
if (segmentDownvoteData) {
segment.hidden = segmentDownvoteData.hidden;
@@ -1127,7 +1127,7 @@ function getEnabledActionTypes(forceFullVideo = false): ActionType[] {
}
async function lockedCategoriesLookup(): Promise<void> {
- const hashPrefix = (await utils.getHash(getVideoID(), 1)).slice(0, 4);
+ const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
if (response.ok) {
diff --git a/src/options.ts b/src/options.ts
index c6e4aae1..23dfe325 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -15,6 +15,7 @@ import KeybindComponent from "./components/options/KeybindComponent";
import { showDonationLink } from "./utils/configUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
+import { getHash } from "@ajayyy/maze-utils/lib/hash";
const utils = new Utils();
let embed = false;
@@ -532,7 +533,7 @@ function activatePrivateTextChange(element: HTMLElement) {
case "userID":
if (Config.config[option]) {
utils.asyncRequestToServer("GET", "/api/userInfo", {
- publicUserID: utils.getHash(Config.config[option]),
+ publicUserID: getHash(Config.config[option]),
values: ["warnings", "banned"]
}).then((result) => {
const userInfo = JSON.parse(result.responseText);
diff --git a/src/popup.ts b/src/popup.ts
index edd4e9e5..2f988119 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -28,6 +28,7 @@ import GenericNotice from "./render/GenericNotice";
import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey";
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
+import { getHash } from "@ajayyy/maze-utils/lib/hash";
const utils = new Utils();
@@ -231,7 +232,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.optionsButton.addEventListener("click", openOptions);
PageElements.helpButton.addEventListener("click", openHelp);
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
- PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await utils.getHash(Config.config.userID)));
+ PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await getHash(Config.config.userID)));
// Forward click events
if (window !== window.top) {
@@ -284,7 +285,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
if (!Config.config.payments.freeAccess && !noRefreshFetchingChaptersAllowed()) values.push("freeChaptersAccess");
utils.asyncRequestToServer("GET", "/api/userInfo", {
- publicUserID: await utils.getHash(Config.config.userID),
+ publicUserID: await getHash(Config.config.userID),
values
}).then((res) => {
if (res.status === 200) {
diff --git a/src/types.ts b/src/types.ts
index b7eff4c0..5ff683a7 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -26,8 +26,6 @@ export interface ContentContainer {
};
}
-export type HashedValue = string & { __hashBrand: unknown };
-
export interface VideoDurationResponse {
duration: number;
}
diff --git a/src/utils.ts b/src/utils.ts
index dbcbc545..cb5e9a34 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,6 +1,7 @@
import Config, { VideoDownvotes } from "./config";
-import { CategorySelection, SponsorTime, BackgroundScriptContainer, Registration, HashedValue, VideoID, SponsorHideType } from "./types";
+import { CategorySelection, SponsorTime, BackgroundScriptContainer, Registration, VideoID, SponsorHideType } from "./types";
+import { getHash, HashedValue } from "@ajayyy/maze-utils/lib/hash";
import * as CompileConfig from "../config.json";
import { waitFor } from "@ajayyy/maze-utils";
import { isSafari } from "./utils/configUtils";
@@ -336,25 +337,11 @@ export default class Utils {
return typeof(browser) !== "undefined";
}
- async getHash<T extends string>(value: T, times = 5000): Promise<T & HashedValue> {
- if (times <= 0) return "" as T & HashedValue;
-
- let hashHex: string = value;
- for (let i = 0; i < times; i++) {
- const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(hashHex).buffer);
-
- const hashArray = Array.from(new Uint8Array(hashBuffer));
- hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
- }
-
- return hashHex as T & HashedValue;
- }
-
async addHiddenSegment(videoID: VideoID, segmentUUID: string, hidden: SponsorHideType) {
if (chrome.extension.inIncognitoContext || !Config.config.trackDownvotes) return;
- const hashedVideoID = (await this.getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue;
- const UUIDHash = await this.getHash(segmentUUID, 1);
+ const hashedVideoID = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue;
+ const UUIDHash = await getHash(segmentUUID, 1);
const allDownvotes = Config.local.downvotedSegments;
const currentVideoData = allDownvotes[hashedVideoID] || { segments: [], lastAccess: 0 };
diff --git a/src/utils/licenseKey.ts b/src/utils/licenseKey.ts
index 77eca21d..67487faf 100644
--- a/src/utils/licenseKey.ts
+++ b/src/utils/licenseKey.ts
@@ -1,6 +1,7 @@
import Config from "../config";
import Utils from "../utils";
import * as CompileConfig from "../../config.json";
+import { getHash } from "@ajayyy/maze-utils/lib/hash";
const utils = new Utils();
@@ -53,7 +54,7 @@ export async function fetchingChaptersAllowed(): Promise<boolean> {
// Check for free access if no license key, and it is the first time
const result = await utils.asyncRequestToServer("GET", "/api/userInfo", {
value: "freeChaptersAccess",
- publicUserID: await utils.getHash(Config.config.userID)
+ publicUserID: await getHash(Config.config.userID)
});
try {
diff --git a/src/utils/warnings.ts b/src/utils/warnings.ts
index 0ff3980c..f4618009 100644
--- a/src/utils/warnings.ts
+++ b/src/utils/warnings.ts
@@ -1,4 +1,5 @@
import { objectToURI } from "@ajayyy/maze-utils";
+import { getHash } from "@ajayyy/maze-utils/lib/hash";
import Config from "../config";
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
import { ContentContainer } from "../types";
@@ -13,7 +14,7 @@ export interface ChatConfig {
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
const userInfo = await utils.asyncRequestToServer("GET", "/api/userInfo", {
- publicUserID: await utils.getHash(Config.config.userID),
+ publicUserID: await getHash(Config.config.userID),
values: ["warningReason"]
});
@@ -21,7 +22,7 @@ export async function openWarningDialog(contentContainer: ContentContainer): Pro
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
- const publicUserID = await utils.getHash(Config.config.userID);
+ const publicUserID = await getHash(Config.config.userID);
let notice: GenericNotice = null;
const options: NoticeOptions = {