mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
remove js-sha256 dependency, use native hashing function
This commit is contained in:
parent
4dc4160215
commit
5bc12e52f3
4 changed files with 15 additions and 19 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -10494,11 +10494,6 @@
|
||||||
"traverse": "0.4.x"
|
"traverse": "0.4.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"js-sha256": {
|
|
||||||
"version": "0.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
|
|
||||||
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
|
|
||||||
},
|
|
||||||
"js-tokens": {
|
"js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
"babel-loader": "^8.0.6",
|
"babel-loader": "^8.0.6",
|
||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"concurrently": "^5.1.0",
|
"concurrently": "^5.1.0",
|
||||||
"js-sha256": "^0.9.0",
|
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
"react-dom": "^16.12.0"
|
"react-dom": "^16.12.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -544,7 +544,7 @@ function incorrectVideoCheck(videoID?: string, sponsorTime?: SponsorTime): boole
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sponsorsLookup(id: string) {
|
async function sponsorsLookup(id: string) {
|
||||||
video = document.querySelector('video') // Youtube video player
|
video = document.querySelector('video') // Youtube video player
|
||||||
//there is no video here
|
//there is no video here
|
||||||
if (video == null) {
|
if (video == null) {
|
||||||
|
@ -621,7 +621,8 @@ function sponsorsLookup(id: string) {
|
||||||
// Check for hashPrefix setting
|
// Check for hashPrefix setting
|
||||||
let getRequest;
|
let getRequest;
|
||||||
if (Config.config.hashPrefix) {
|
if (Config.config.hashPrefix) {
|
||||||
getRequest = utils.asyncRequestToServer('GET', "/api/skipSegments/" + utils.getHash(id, 1).substr(0,4), {
|
const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4);
|
||||||
|
getRequest = utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
|
||||||
categories
|
categories
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
15
src/utils.ts
15
src/utils.ts
|
@ -1,6 +1,5 @@
|
||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
import { CategorySelection, SponsorTime, FetchResponse } from "./types";
|
import { CategorySelection, SponsorTime, FetchResponse } from "./types";
|
||||||
import { sha256 } from 'js-sha256';
|
|
||||||
|
|
||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
|
|
||||||
|
@ -380,17 +379,19 @@ class Utils {
|
||||||
return typeof(browser) !== "undefined";
|
return typeof(browser) !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
getHash(value: string, times=5000): string {
|
async getHash(value: string, times = 5000): Promise<string> {
|
||||||
if (times <= 0) return "";
|
if (times <= 0) return "";
|
||||||
|
|
||||||
|
let hashBuffer = new TextEncoder().encode(value).buffer;
|
||||||
|
|
||||||
for (let i = 0; i < times; i++) {
|
for (let i = 0; i < times; i++) {
|
||||||
let hash = sha256.create();
|
hashBuffer = await crypto.subtle.digest('SHA-256', hashBuffer);
|
||||||
hash.update(value);
|
|
||||||
hash.hex();
|
|
||||||
value = hash.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
|
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||||
|
|
||||||
|
return hashHex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue