mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-31 14:51:13 +03:00
Fix type issues
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject } from "./types";
|
import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject, UnEncodedSegmentTimes as UnencodedSegmentTimes } from "./types";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
@@ -247,7 +247,7 @@ const Config: SBObject = {
|
|||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
function encodeStoredItem<T>(data: T): T | Array<[string, Array<SponsorTime>]> {
|
function encodeStoredItem<T>(data: T): T | UnencodedSegmentTimes {
|
||||||
// if data is SBMap convert to json for storing
|
// if data is SBMap convert to json for storing
|
||||||
if(!(data instanceof SBMap)) return data;
|
if(!(data instanceof SBMap)) return data;
|
||||||
return Array.from(data.entries()).filter((element) => element[1] === []); // Remove empty entries
|
return Array.from(data.entries()).filter((element) => element[1] === []); // Remove empty entries
|
||||||
@@ -265,7 +265,7 @@ function decodeStoredItem<T>(id: string, data: T): T | SBMap<string, SponsorTime
|
|||||||
if (Config.defaults[id] instanceof SBMap) {
|
if (Config.defaults[id] instanceof SBMap) {
|
||||||
try {
|
try {
|
||||||
if (!Array.isArray(data)) return data;
|
if (!Array.isArray(data)) return data;
|
||||||
return new SBMap(id, data);
|
return new SBMap(id, data as UnencodedSegmentTimes);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("Failed to parse SBMap: " + id);
|
console.error("Failed to parse SBMap: " + id);
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/types.ts
42
src/types.ts
@@ -1,7 +1,7 @@
|
|||||||
import SubmissionNotice from "./render/SubmissionNotice";
|
import SubmissionNotice from "./render/SubmissionNotice";
|
||||||
import SkipNoticeComponent from "./components/SkipNoticeComponent";
|
import SkipNoticeComponent from "./components/SkipNoticeComponent";
|
||||||
|
|
||||||
interface ContentContainer {
|
export interface ContentContainer {
|
||||||
(): {
|
(): {
|
||||||
vote: (type: number, UUID: string, category?: string, skipNotice?: SkipNoticeComponent) => void,
|
vote: (type: number, UUID: string, category?: string, skipNotice?: SkipNoticeComponent) => void,
|
||||||
dontShowNoticeAgain: () => void,
|
dontShowNoticeAgain: () => void,
|
||||||
@@ -22,34 +22,34 @@ interface ContentContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FetchResponse {
|
export interface FetchResponse {
|
||||||
responseText: string,
|
responseText: string,
|
||||||
status: number,
|
status: number,
|
||||||
ok: boolean
|
ok: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VideoDurationResponse {
|
export interface VideoDurationResponse {
|
||||||
duration: number;
|
duration: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CategorySkipOption {
|
export enum CategorySkipOption {
|
||||||
ShowOverlay,
|
ShowOverlay,
|
||||||
ManualSkip,
|
ManualSkip,
|
||||||
AutoSkip
|
AutoSkip
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CategorySelection {
|
export interface CategorySelection {
|
||||||
name: string;
|
name: string;
|
||||||
option: CategorySkipOption
|
option: CategorySkipOption
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SponsorHideType {
|
export enum SponsorHideType {
|
||||||
Visible = undefined,
|
Visible = undefined,
|
||||||
Downvoted = 1,
|
Downvoted = 1,
|
||||||
MinimumDuration
|
MinimumDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SponsorTime {
|
export interface SponsorTime {
|
||||||
segment: number[];
|
segment: number[];
|
||||||
UUID: string;
|
UUID: string;
|
||||||
|
|
||||||
@@ -58,13 +58,13 @@ interface SponsorTime {
|
|||||||
hidden?: SponsorHideType;
|
hidden?: SponsorHideType;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PreviewBarOption {
|
export interface PreviewBarOption {
|
||||||
color: string,
|
color: string,
|
||||||
opacity: string
|
opacity: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface Registration {
|
export interface Registration {
|
||||||
message: string,
|
message: string,
|
||||||
id: string,
|
id: string,
|
||||||
allFrames: boolean,
|
allFrames: boolean,
|
||||||
@@ -73,12 +73,12 @@ interface Registration {
|
|||||||
matches: string[]
|
matches: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BackgroundScriptContainer {
|
export interface BackgroundScriptContainer {
|
||||||
registerFirefoxContentScript: (opts: Registration) => void,
|
registerFirefoxContentScript: (opts: Registration) => void,
|
||||||
unregisterFirefoxContentScript: (id: string) => void
|
unregisterFirefoxContentScript: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VideoInfo {
|
export interface VideoInfo {
|
||||||
responseContext: {
|
responseContext: {
|
||||||
serviceTrackingParams: Array<{service: string, params: Array<{key: string, value: string}>}>,
|
serviceTrackingParams: Array<{service: string, params: Array<{key: string, value: string}>}>,
|
||||||
webResponseContextExtensionData: {
|
webResponseContextExtensionData: {
|
||||||
@@ -154,22 +154,8 @@ interface VideoInfo {
|
|||||||
messages: unknown;
|
messages: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoID = string;
|
export type VideoID = string;
|
||||||
|
|
||||||
type StorageChangesObject = { [key: string]: chrome.storage.StorageChange };
|
export type StorageChangesObject = { [key: string]: chrome.storage.StorageChange };
|
||||||
|
|
||||||
export {
|
export type UnEncodedSegmentTimes = [string, SponsorTime[]][];
|
||||||
FetchResponse,
|
|
||||||
VideoDurationResponse,
|
|
||||||
ContentContainer,
|
|
||||||
CategorySelection,
|
|
||||||
CategorySkipOption,
|
|
||||||
SponsorTime,
|
|
||||||
VideoID,
|
|
||||||
SponsorHideType,
|
|
||||||
PreviewBarOption,
|
|
||||||
Registration,
|
|
||||||
BackgroundScriptContainer,
|
|
||||||
VideoInfo,
|
|
||||||
StorageChangesObject,
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user