aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoe Dowd <[email protected]>2020-09-04 00:05:41 +0100
committerJoe Dowd <[email protected]>2020-09-04 00:05:41 +0100
commit40d522694dc4bd108dec0e2ee7af14826ca7c0f6 (patch)
tree4e42e0f109d6ce6818596823c0ed219cd3bbba49
parent3ec3a011281f946b749335aafaf5aad8d64d7422 (diff)
downloadSponsorBlock-40d522694dc4bd108dec0e2ee7af14826ca7c0f6.tar.gz
SponsorBlock-40d522694dc4bd108dec0e2ee7af14826ca7c0f6.zip
Added has prefix implementation (no config page)
-rw-r--r--package-lock.json5
-rw-r--r--package.json1
-rw-r--r--src/config.ts2
-rw-r--r--src/content.ts34
-rw-r--r--src/utils.ts15
5 files changed, 52 insertions, 5 deletions
diff --git a/package-lock.json b/package-lock.json
index 5cd00a3d..7e806d7e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10494,6 +10494,11 @@
"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": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
diff --git a/package.json b/package.json
index 50d274e5..5d42ab1c 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"concurrently": "^5.1.0",
+ "js-sha256": "^0.9.0",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
diff --git a/src/config.ts b/src/config.ts
index 5d34df6b..9d830116 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -35,6 +35,7 @@ interface SBConfig {
audioNotificationOnSkip,
checkForUnlistedVideos: boolean,
testingServer: boolean,
+ hashPrefix: boolean
// What categories should be skipped
categorySelections: CategorySelection[],
@@ -166,6 +167,7 @@ var Config: SBObject = {
audioNotificationOnSkip: false,
checkForUnlistedVideos: false,
testingServer: false,
+ hashPrefix: false,
categorySelections: [{
name: "sponsor",
diff --git a/src/content.ts b/src/content.ts
index 7f75ada0..37999d99 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -618,12 +618,36 @@ function sponsorsLookup(id: string) {
categories.push(categorySelection.name);
}
- utils.asyncRequestToServer('GET', "/api/skipSegments", {
- videoID: id,
- categories
- }).then(async (response: FetchResponse) => {
+ // Check for hashPrefix setting
+ let getRequest;
+ if (Config.config.hashPrefix) {
+ getRequest = utils.asyncRequestToServer('GET', "/api/skipSegments/"+utils.getHash(id, 1).substr(0,4), {
+ categories
+ });
+ } else {
+ getRequest = utils.asyncRequestToServer('GET', "/api/skipSegments", {
+ videoID: id,
+ categories
+ });
+ }
+ getRequest.then(async (response: FetchResponse) => {
if (response?.ok) {
- let recievedSegments: SponsorTime[] = JSON.parse(response.responseText);
+ let getResult = JSON.parse(response.responseText);
+ if (Config.config.hashPrefix) {
+ getResult = getResult.filter((video) => {
+ return video.videoID = id;
+ });
+ if (getResult.length === 1) {
+ getResult = getResult[0].segments;
+ if (getResult.length === 0) { // return if no regments found
+ return;
+ }
+ } else { // return if no video found
+ return;
+ }
+ }
+
+ let recievedSegments: SponsorTime[] = getResult;
if (!recievedSegments.length) {
console.error("[SponsorBlock] Server returned malformed response: " + JSON.stringify(recievedSegments));
return;
diff --git a/src/utils.ts b/src/utils.ts
index 43cdc68e..d95da7dc 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,5 +1,6 @@
import Config from "./config";
import { CategorySelection, SponsorTime, FetchResponse } from "./types";
+import { sha256 } from 'js-sha256';
import * as CompileConfig from "../config.json";
@@ -378,6 +379,20 @@ class Utils {
isFirefox(): boolean {
return typeof(browser) !== "undefined";
}
+
+ getHash(value: string, times=5000): string {
+ if (times <= 0) return "";
+
+ for (let i = 0; i < times; i++) {
+ let hash = sha256.create();
+ hash.update(value);
+ hash.hex();
+ value = hash.toString();
+ }
+
+ return value;
+ }
+
}
export default Utils; \ No newline at end of file