mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 12:07:11 +03:00
chore(types): strongly type BackgroundScriptContainer et al
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
|
|
||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
import { Registration } from "./types";
|
||||||
// Make the config public for debugging purposes
|
// Make the config public for debugging purposes
|
||||||
(<any> window).SB = Config;
|
(<any> window).SB = Config;
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ chrome.runtime.onInstalled.addListener(function (object) {
|
|||||||
*
|
*
|
||||||
* @param {JSON} options
|
* @param {JSON} options
|
||||||
*/
|
*/
|
||||||
function registerFirefoxContentScript(options) {
|
function registerFirefoxContentScript(options: Registration) {
|
||||||
const oldRegistration = contentScriptRegistrations[options.id];
|
const oldRegistration = contentScriptRegistrations[options.id];
|
||||||
if (oldRegistration) oldRegistration.unregister();
|
if (oldRegistration) oldRegistration.unregister();
|
||||||
|
|
||||||
|
|||||||
21
src/types.ts
21
src/types.ts
@@ -63,6 +63,21 @@ interface PreviewBarOption {
|
|||||||
opacity: string
|
opacity: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface Registration {
|
||||||
|
message: string,
|
||||||
|
id: string,
|
||||||
|
allFrames: boolean,
|
||||||
|
js: browser.extensionTypes.ExtensionFileOrCode[],
|
||||||
|
css: browser.extensionTypes.ExtensionFileOrCode[],
|
||||||
|
matches: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BackgroundScriptContainer {
|
||||||
|
registerFirefoxContentScript: (opts: Registration) => void,
|
||||||
|
unregisterFirefoxContentScript: (id: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
type VideoID = string;
|
type VideoID = string;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -74,5 +89,7 @@ export {
|
|||||||
SponsorTime,
|
SponsorTime,
|
||||||
VideoID,
|
VideoID,
|
||||||
SponsorHideType,
|
SponsorHideType,
|
||||||
PreviewBarOption
|
PreviewBarOption,
|
||||||
};
|
Registration,
|
||||||
|
BackgroundScriptContainer
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
import { CategorySelection, SponsorTime, FetchResponse } from "./types";
|
import { CategorySelection, SponsorTime, FetchResponse, BackgroundScriptContainer, Registration } from "./types";
|
||||||
|
|
||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
|
||||||
// Contains functions needed from the background script
|
// Contains functions needed from the background script
|
||||||
backgroundScriptContainer: any = null;
|
backgroundScriptContainer: BackgroundScriptContainer | null = null;
|
||||||
|
|
||||||
// Used to add content scripts and CSS required
|
// Used to add content scripts and CSS required
|
||||||
js = [
|
js = [
|
||||||
@@ -19,7 +19,7 @@ class Utils {
|
|||||||
"popup.css"
|
"popup.css"
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor(backgroundScriptContainer?: any) {
|
constructor(backgroundScriptContainer?: BackgroundScriptContainer) {
|
||||||
this.backgroundScriptContainer = backgroundScriptContainer;
|
this.backgroundScriptContainer = backgroundScriptContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ class Utils {
|
|||||||
firefoxCSS.push({file});
|
firefoxCSS.push({file});
|
||||||
}
|
}
|
||||||
|
|
||||||
const registration = {
|
const registration: Registration = {
|
||||||
message: "registerContentScript",
|
message: "registerContentScript",
|
||||||
id: "invidious",
|
id: "invidious",
|
||||||
allFrames: true,
|
allFrames: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user