mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-14 07:27:05 +03:00
Added has prefix implementation (no config page)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
15
src/utils.ts
15
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;
|
||||
Reference in New Issue
Block a user