@violentmonkey/types
    Preparing search index...

    Interface VMScriptGMObjectVMExtensions

    Aliases for GM_ methods that are not included in Greasemonkey4 API

    interface VMScriptGMObjectVMExtensions {
        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>;
        };
        deleteValues: (names: string[]) => Promise<void>;
        getResourceText: (name: string) => string;
        log: (...args: any) => void;
        removeValueChangeListener: (listenerId: string) => void;
        setValues: (values: GenericObject) => Promise<void>;
        unregisterMenuCommand: (caption: string) => void;
        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

    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

    log: (...args: any) => void

    Type Declaration

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

        Parameters

        • ...args: any

        Returns void

    removeValueChangeListener: (listenerId: string) => void

    Type Declaration

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

        Parameters

        • listenerId: string

        Returns 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