feat: wire market plugin controls
This commit is contained in:
+34
-1
@@ -1 +1,34 @@
|
||||
export {};
|
||||
import {
|
||||
createMarketController,
|
||||
type CreateMarketControllerOptions
|
||||
} from "./market/index";
|
||||
|
||||
interface BootContentScriptOptions {
|
||||
createMarketController?: (
|
||||
options: CreateMarketControllerOptions
|
||||
) => { ready: Promise<void> };
|
||||
document?: Document;
|
||||
window?: Window;
|
||||
}
|
||||
|
||||
export async function bootContentScript(
|
||||
options: BootContentScriptOptions = {}
|
||||
): Promise<{ ready: Promise<void> } | null> {
|
||||
const currentWindow = options.window ?? window;
|
||||
const currentDocument = options.document ?? document;
|
||||
const controllerFactory =
|
||||
options.createMarketController ?? createMarketController;
|
||||
|
||||
if (!isMarketPage(currentWindow.location.href)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return controllerFactory({
|
||||
document: currentDocument,
|
||||
window: currentWindow
|
||||
});
|
||||
}
|
||||
|
||||
function isMarketPage(url: string): boolean {
|
||||
return url.startsWith("https://xingtu.cn/ad/creator/market");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user