MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / MockUserScripts

Class MockUserScripts

packages/chrome-extension-mock/user_scripts.ts:1–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export default class MockUserScripts {
2 // ---- Types ----
3 public static ExecutionWorld = {
4 MAIN: "MAIN",
5 USER_SCRIPT: "USER_SCRIPT",
6 } as const;
7
8 public scripts: any[] = [];
9 public worlds: any[] = [];
10
11 // ---- configureWorld ----
12 configureWorld(properties: any): Promise<void>;
13 configureWorld(properties: any, callback: () => void): void;
14 configureWorld(properties: any, callback?: () => void): Promise<void> | void {
15 // console.log("configureWorld called with:", properties);
16 this.worlds.push(properties);
17 if (callback) callback();
18 else return Promise.resolve();
19 }
20
21 // ---- getScripts ----
22 getScripts(filter?: any): Promise<any[]>;
23 getScripts(filter: any, callback: (scripts: any[]) => void): void;
24 getScripts(filter?: any, callback?: (scripts: any[]) => void): Promise<any[]> | void {
25 // console.log("getScripts called with:", filter);
26 let result = this.scripts;
27 if (filter?.ids) {
28 result = this.scripts.filter((s) => filter.ids.includes(s.id));
29 }
30 if (callback) callback(result);
31 else return Promise.resolve(result);
32 }
33
34 // ---- getWorldConfigurations ----
35 getWorldConfigurations(): Promise<any[]>;
36 getWorldConfigurations(callback: (worlds: any[]) => void): void;
37 getWorldConfigurations(callback?: (worlds: any[]) => void): Promise<any[]> | void {
38 // console.log("getWorldConfigurations called");
39 if (callback) callback(this.worlds);
40 else return Promise.resolve(this.worlds);
41 }
42
43 // ---- execute ----
44 execute(injection: any): Promise<any[]>;
45 execute(injection: any, callback: (result: any[]) => void): void;
46 execute(injection: any, callback?: (result: any[]) => void): Promise<any[]> | void {
47 // console.log("execute called with:", injection);
48 const result = {
49 documentId: "dummy-doc-id",
50 frameId: injection.target.frameIds?.[0] ?? 0,
51 result: "dummy-result",
52 };
53 if (callback) callback([result]);
54 else return Promise.resolve([result]);
55 }
56
57 // ---- register ----
58 register(scripts: any[]): Promise<void>;
59 register(scripts: any[], callback: () => void): void;
60 register(scripts: any[], callback?: () => void): Promise<void> | void {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected