~glacambre/firenvim

ref: 501a2485049df810baba19ead14831c3929416fd firenvim/src/page/proxy.ts -rw-r--r-- 873 bytes
501a2485glacambre Trigger a bunch of events on setElementContent 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { getFunctions } from "./functions";

// We don't need to give real values to getFunctions since we're only trying to
// get the name of functions that exist in the page.
const functions = getFunctions({} as any);

export const page = {} as typeof functions;

let funcName: keyof typeof functions;
for (funcName in functions) {
    if (!functions.hasOwnProperty(funcName)) { // Make tslint happy
        continue;
    }
    // We need this local variable because Typescript won't let us give type
    // annotations to variables declared on for(... in ...) loops
    const func = funcName;
    page[func] = ((...arr: any[]) => {
        return browser.runtime.sendMessage({
            args: {
                args: arr,
                function: func,
            },
            function: "messageOwnTab",
        });
    }) as ((typeof functions)[typeof func]);
}