aboutsummaryrefslogtreecommitdiff
path: root/src/gm.ts
blob: 3338516a21862ac60cc4d92046e1ffb2a42570a0 (plain) (blame)
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
27
28
29
/**
 * UserScript APIs
 */
declare const GM: {
    /** https://www.tampermonkey.net/documentation.php#GM_info */
    info: Record<string, any>;

    /** https://www.tampermonkey.net/documentation.php#GM_registerMenuCommand */
    registerMenuCommand(
        name: string,
        fn: () => any,
        accessKey?: string
    ): Promise<number>;

    /** https://github.com/Tampermonkey/tampermonkey/issues/881#issuecomment-639705679 */
    addElement<K extends keyof HTMLElementTagNameMap>(
        tagName: K,
        properties: Record<string, any>
    ): Promise<HTMLElementTagNameMap[K]>;
};
export const _GM = (typeof GM === "object" ? GM : undefined) as GM;

type GM = typeof GM;

export const isGmAvailable = (requiredMethod: keyof GM = "info"): boolean => {
    return (
        typeof GM !== "undefined" && typeof GM[requiredMethod] !== "undefined"
    );
};