@violentmonkey/types
    Preparing search index...

    Interface VMScriptGMObject

    interface VMScriptGMObject {
        addElement: {
            (tagName: string, attributes?: Record<string, string>): HTMLElement;
            (
                parentNode: HTMLElement,
                tagName: string,
                attributes?: Record<string, string>,
            ): HTMLElement;
        };
        addStyle: (css: string) => HTMLStyleElement;
        addValueChangeListener: <T>(
            name: string,
            callback: VMScriptGMValueChangeCallback<T>,
        ) => string;
        cookie: {
            delete: (opts: _RemoveDetails | CookieDetails) => Promise<void>;
            list: (
                opts:
                    | _GetAllDetails
                    | {
                        domain?: string;
                        name?: string;
                        partitionKey?: CookiePartitionKey;
                        path?: string;
                        secure?: boolean;
                        session?: boolean;
                        storeId?: string;
                        url?: string;
                    },
            ) => Promise<Cookie | Cookie>;
            set: (
                opts:
                    | _SetDetails
                    | {
                        domain?: string;
                        expirationDate?: number;
                        httpOnly?: boolean;
                        name?: string;
                        partitionKey?: CookiePartitionKey;
                        path?: string;
                        sameSite?: SameSiteStatus;
                        secure?: boolean;
                        storeId?: string;
                        url: string;
                        value?: string;
                    },
            ) => Promise<void>;
        };
        deleteValue: (name: string) => Promise<void>;
        deleteValues: (names: string[]) => Promise<void>;
        getResourceText: (name: string) => string;
        getResourceUrl: (name: string, isBlobUrl?: boolean) => Promise<string>;
        getValue: <T>(name: string, defaultValue?: T) => Promise<T>;
        info: VMScriptGMInfoObject;
        listValues: () => Promise<string[]>;
        log: (...args: any) => void;
        notification: {
            (options: VMScriptGMNotificationOptions): VMScriptGMNotificationControl;
            (
                text: string,
                title?: string,
                image?: string,
                onclick?: () => void,
            ): VMScriptGMNotificationControl;
        };
        openInTab: {
            (url: string, options?: VMScriptGMTabOptions): VMScriptGMTabControl;
            (url: string, openInBackground?: boolean): VMScriptGMTabControl;
        };
        registerMenuCommand: (
            caption: string,
            onClick: (event: MouseEvent | KeyboardEvent) => void,
            options?: {
                autoClose?: boolean;
                icon?: string;
                id?: string;
                title?: string;
            },
        ) => string;
        removeValueChangeListener: (listenerId: string) => void;
        setClipboard: (data: string, type?: string) => void;
        setValue: <T>(name: string, value: T) => Promise<void>;
        setValues: (values: GenericObject) => Promise<void>;
        unregisterMenuCommand: (caption: string) => void;
        unsafeWindow: Window;
        xmlHttpRequest: <T = string | object | ArrayBuffer | Blob | Document>(
            details: VMScriptGMXHRDetails<T>,
        ) => Promise<T> & VMScriptXHRControl;
        download(options: VMScriptGMDownloadOptions): void | Promise<Blob>;
        download(url: string, name: string): void | Promise<Blob>;
        getValues(names: string[]): Promise<GenericObject>;
        getValues(namesWithDefaults: GenericObject): Promise<GenericObject>;
    }

    Hierarchy (View Summary)

    Index
    addElement: {
        (tagName: string, attributes?: Record<string, string>): HTMLElement;
        (
            parentNode: HTMLElement,
            tagName: string,
            attributes?: Record<string, string>,
        ): HTMLElement;
    }

    Type Declaration

      • (tagName: string, attributes?: Record<string, string>): HTMLElement
      • Appends and returns an element with the specified attributes.

        Examples:

        // using a private function in `onload`
        let el = GM_addElement('script', { src: 'https://....' });
        el.onload = () => console.log('loaded', el);

        // same as GM_addStyle('a { color:red }')
        let el = GM_addElement('style', { textContent: 'a { color:red }' });

        // appending to an arbitrary node
        let el = GM_addElement(parentElement.shadowRoot, 'iframe', { src: url });

        Parameters

        • tagName: string

          A tag name like script. Any valid HTML tag can be used, but the only motivation for this API was to add script, link, style elements when they are disallowed by a strict Content-Security-Policy of the site e.g. github.com, twitter.com.

        • Optionalattributes: Record<string, string>

          The keys are HTML attributes, not DOM properties, except textContent which sets DOM property textContent. The values are strings so if you want to assign a private function to onload you can do it after the element is created.

        Returns HTMLElement

      • (
            parentNode: HTMLElement,
            tagName: string,
            attributes?: Record<string, string>,
        ): HTMLElement
      • Appends and returns an element with the specified attributes.

        Examples:

        // using a private function in `onload`
        let el = GM_addElement('script', { src: 'https://....' });
        el.onload = () => console.log('loaded', el);

        // same as GM_addStyle('a { color:red }')
        let el = GM_addElement('style', { textContent: 'a { color:red }' });

        // appending to an arbitrary node
        let el = GM_addElement(parentElement.shadowRoot, 'iframe', { src: url });

        Parameters

        • parentNode: HTMLElement

          The parent node to which the new node will be appended. It can be inside ShadowDOM: someElement.shadowRoot. When omitted, it'll be determined automatically:

          • document.head (<head>) for script, link, style, meta tags.
          • document.body (<body>) for other tags or when there's no <head>.
          • document.documentElement (<html> or an XML root node) otherwise.
        • tagName: string

          A tag name like script. Any valid HTML tag can be used, but the only motivation for this API was to add script, link, style elements when they are disallowed by a strict Content-Security-Policy of the site e.g. github.com, twitter.com.

        • Optionalattributes: Record<string, string>

          The keys are HTML attributes, not DOM properties, except textContent which sets DOM property textContent. The values are strings so if you want to assign a private function to onload you can do it after the element is created.

        Returns HTMLElement

    addStyle: (css: string) => HTMLStyleElement

    Type Declaration

      • (css: string): HTMLStyleElement
      • Appends and returns a <style> element with the specified CSS.

        Parameters

        • css: string

        Returns HTMLStyleElement

    addValueChangeListener: <T>(
        name: string,
        callback: VMScriptGMValueChangeCallback<T>,
    ) => string

    Type Declaration

    cookie: {
        delete: (opts: _RemoveDetails | CookieDetails) => Promise<void>;
        list: (
            opts:
                | _GetAllDetails
                | {
                    domain?: string;
                    name?: string;
                    partitionKey?: CookiePartitionKey;
                    path?: string;
                    secure?: boolean;
                    session?: boolean;
                    storeId?: string;
                    url?: string;
                },
        ) => Promise<Cookie | Cookie>;
        set: (
            opts:
                | _SetDetails
                | {
                    domain?: string;
                    expirationDate?: number;
                    httpOnly?: boolean;
                    name?: string;
                    partitionKey?: CookiePartitionKey;
                    path?: string;
                    sameSite?: SameSiteStatus;
                    secure?: boolean;
                    storeId?: string;
                    url: string;
                    value?: string;
                },
        ) => Promise<void>;
    }

    Type Declaration

    • delete: (opts: _RemoveDetails | CookieDetails) => Promise<void>
    • list: (
          opts:
              | _GetAllDetails
              | {
                  domain?: string;
                  name?: string;
                  partitionKey?: CookiePartitionKey;
                  path?: string;
                  secure?: boolean;
                  session?: boolean;
                  storeId?: string;
                  url?: string;
              },
      ) => Promise<Cookie | Cookie>

      httpOnly cookies are listed only when the HTTP-only option is enabled for the script and globally in the extension

    • set: (
          opts:
              | _SetDetails
              | {
                  domain?: string;
                  expirationDate?: number;
                  httpOnly?: boolean;
                  name?: string;
                  partitionKey?: CookiePartitionKey;
                  path?: string;
                  sameSite?: SameSiteStatus;
                  secure?: boolean;
                  storeId?: string;
                  url: string;
                  value?: string;
              },
      ) => Promise<void>

      httpOnly cookies are allowed only when the HTTP-only option is enabled for the script and globally in the extension

    VM2.35.1

    deleteValue: (name: string) => Promise<void>
    deleteValues: (names: string[]) => Promise<void>

    VM2.19.1

    getResourceText: (name: string) => string

    Type Declaration

      • (name: string): string
      • Retrieves a text resource from the Metadata Block.

        Parameters

        • name: string

          Name of a resource defined in the Metadata Block.

        Returns string

    getResourceUrl: (name: string, isBlobUrl?: boolean) => Promise<string>
    getValue: <T>(name: string, defaultValue?: T) => Promise<T>
    listValues: () => Promise<string[]>
    log: (...args: any) => void

    Type Declaration

      • (...args: any): void
      • The original console.log

        Parameters

        • ...args: any

        Returns void

    notification: {
        (options: VMScriptGMNotificationOptions): VMScriptGMNotificationControl;
        (
            text: string,
            title?: string,
            image?: string,
            onclick?: () => void,
        ): VMScriptGMNotificationControl;
    }

    Type Declaration

    openInTab: {
        (url: string, options?: VMScriptGMTabOptions): VMScriptGMTabControl;
        (url: string, openInBackground?: boolean): VMScriptGMTabControl;
    }

    Type Declaration

      • (url: string, options?: VMScriptGMTabOptions): VMScriptGMTabControl
      • Opens URL in a new tab.

        Parameters

        • url: string

          The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs.

        • Optionaloptions: VMScriptGMTabOptions

        Returns VMScriptGMTabControl

      • (url: string, openInBackground?: boolean): VMScriptGMTabControl
      • Opens URL in a new tab.

        Parameters

        • url: string

          The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs.

        • OptionalopenInBackground: boolean

          Open the tab in background. Note, this is a reverse of the first usage method so for example true is the same as { active: false }.

        Returns VMScriptGMTabControl

    registerMenuCommand: (
        caption: string,
        onClick: (event: MouseEvent | KeyboardEvent) => void,
        options?: {
            autoClose?: boolean;
            icon?: string;
            id?: string;
            title?: string;
        },
    ) => string

    Type Declaration

      • (
            caption: string,
            onClick: (event: MouseEvent | KeyboardEvent) => void,
            options?: {
                autoClose?: boolean;
                icon?: string;
                id?: string;
                title?: string;
            },
        ): string
      • Registers a command in Violentmonkey popup menu. Returns the command's id since VM2.12.5, see description of the id parameter. If you want to add a shortcut, please see @violentmonkey/shortcut.

        Parameters

        • caption: string

          The name to show in the popup menu.

        • onClick: (event: MouseEvent | KeyboardEvent) => void

          Callback function when the command is clicked in the menu.

        • Optionaloptions: { autoClose?: boolean; icon?: string; id?: string; title?: string }

          VM2.15.9

          • OptionalautoClose?: boolean

            Default: true. Whether to auto-close the popup after the user invoked the command.

          • Optionalicon?: string

            VM2.31.1

          • Optionalid?: string

            Default: the caption parameter. In 2.15.9-2.16.1 the default was a randomly generated string.

          • Optionaltitle?: string

            A hint shown in the status bar when hovering the command.

        Returns string

    removeValueChangeListener: (listenerId: string) => void

    Type Declaration

      • (listenerId: string): void
      • Removes a change listener by its ID.

        Parameters

        • listenerId: string

        Returns void

    setClipboard: (data: string, type?: string) => void

    Type Declaration

      • (data: string, type?: string): void
      • Sets data to system clipboard.

        Parameters

        • data: string

          The data to be copied to system clipboard.

        • Optionaltype: string

          The MIME type of data to copy. Default as text/plain.

        Returns void

    setValue: <T>(name: string, value: T) => Promise<void>
    setValues: (values: GenericObject) => Promise<void>

    VM2.19.1

    unregisterMenuCommand: (caption: string) => void

    Type Declaration

      • (caption: string): void
      • Unregisters a command which has been registered to Violentmonkey popup menu.

        Parameters

        • caption: string

          The name of command to unregister.

        Returns void

    unsafeWindow: Window
    xmlHttpRequest: <T = string | object | ArrayBuffer | Blob | Document>(
        details: VMScriptGMXHRDetails<T>,
    ) => Promise<T> & VMScriptXHRControl