mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
remove js-sha256 dependency, use native hashing function
This commit is contained in:
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) {
|
||||||
@@ -569,7 +569,7 @@ function sponsorsLookup(id: string) {
|
|||||||
updateAdFlag();
|
updateAdFlag();
|
||||||
|
|
||||||
// Make sure it doesn't get double called with the playing event
|
// Make sure it doesn't get double called with the playing event
|
||||||
if (Math.abs(lastCheckVideoTime - video.currentTime) > 0.3
|
if (Math.abs(lastCheckVideoTime - video.currentTime) > 0.3
|
||||||
|| (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000)) {
|
|| (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000)) {
|
||||||
lastCheckTime = Date.now();
|
lastCheckTime = Date.now();
|
||||||
lastCheckVideoTime = video.currentTime;
|
lastCheckVideoTime = video.currentTime;
|
||||||
@@ -580,7 +580,7 @@ function sponsorsLookup(id: string) {
|
|||||||
});
|
});
|
||||||
video.addEventListener('playing', () => {
|
video.addEventListener('playing', () => {
|
||||||
// Make sure it doesn't get double called with the play event
|
// Make sure it doesn't get double called with the play event
|
||||||
if (Math.abs(lastCheckVideoTime - video.currentTime) > 0.3
|
if (Math.abs(lastCheckVideoTime - video.currentTime) > 0.3
|
||||||
|| (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000)) {
|
|| (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000)) {
|
||||||
lastCheckTime = Date.now();
|
lastCheckTime = Date.now();
|
||||||
lastCheckVideoTime = video.currentTime;
|
lastCheckVideoTime = video.currentTime;
|
||||||
@@ -592,7 +592,7 @@ function sponsorsLookup(id: string) {
|
|||||||
if (!video.paused){
|
if (!video.paused){
|
||||||
// Reset lastCheckVideoTime
|
// Reset lastCheckVideoTime
|
||||||
lastCheckTime = Date.now();
|
lastCheckTime = Date.now();
|
||||||
lastCheckVideoTime = video.currentTime;
|
lastCheckVideoTime = video.currentTime;
|
||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
}
|
}
|
||||||
@@ -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 {
|
||||||
|
|||||||
17
src/utils.ts
17
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,19 +379,21 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Utils;
|
export default Utils;
|
||||||
|
|||||||
Reference in New Issue
Block a user