Interface VMScriptGMObject

interface VMScriptGMObject {
    addElement: {
        (tagName, attributes?): HTMLElement;
        (parentNode, tagName, attributes?): HTMLElement;
    };
    addStyle: ((css) => HTMLStyleElement);
    addValueChangeListener: (<T>(name, callback) => string);
    deleteValue: ((name) => Promise<void>);
    deleteValues: ((names) => Promise<void>);
    download: ((options) => void | Promise<Blob>) | ((url, name) => void | Promise<Blob>);
    getResourceText: ((name) => string);
    getResourceUrl: ((name, isBlobUrl?) => Promise<string>);
    getValue: (<T>(name, defaultValue?) => Promise<T>);
    getValues: ((names) => Promise<GenericObject>) | ((namesWithDefaults) => Promise<GenericObject>);
    info: VMScriptGMInfoObject;
    listValues: (() => Promise<string[]>);
    log: ((...args) => void);
    notification: {
        (options): VMScriptGMNotificationControl;
        (text, title?, image?, onclick?): VMScriptGMNotificationControl;
    };
    openInTab: {
        (url, options?): VMScriptGMTabControl;
        (url, openInBackground?): VMScriptGMTabControl;
    };
    registerMenuCommand: ((caption, onClick, options?) => string);
    removeValueChangeListener: ((listenerId) => void);
    setClipboard: ((data, type?) => void);
    setValue: (<T>(name, value) => Promise<void>);
    setValues: ((values) => Promise<void>);
    unregisterMenuCommand: ((caption) => void);
    unsafeWindow: Window;
    xmlHttpRequest: (<T>(details) => Promise<T> & VMScriptXHRControl);
}

Hierarchy (view full)

Properties

addElement: {
    (tagName, attributes?): HTMLElement;
    (parentNode, tagName, attributes?): HTMLElement;
}

Type declaration

    • (tagName, attributes?): 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.

      • Optional attributes: 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, tagName, attributes?): HTMLElement
    • 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.

      • Optional attributes: 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) => HTMLStyleElement)

Type declaration

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

      Parameters

      • css: string

      Returns HTMLStyleElement

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

Type declaration

    • <T>(name, callback): string
    • Adds a change listener to the storage and returns the listener ID.

      Type Parameters

      • T

      Parameters

      Returns string

deleteValue: ((name) => Promise<void>)

Type declaration

    • (name): Promise<void>
    • Parameters

      • name: string

      Returns Promise<void>

deleteValues: ((names) => Promise<void>)

Type declaration

    • (names): Promise<void>
    • Parameters

      • names: string[]

      Returns Promise<void>

Since

VM2.19.1

download: ((options) => void | Promise<Blob>) | ((url, name) => void | Promise<Blob>)

Type declaration

Type declaration

    • (url, name): void | Promise<Blob>
    • Parameters

      • url: string
      • name: string

      Returns void | Promise<Blob>

getResourceText: ((name) => string)

Type declaration

    • (name): 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, isBlobUrl?) => Promise<string>)

Type declaration

    • (name, isBlobUrl?): Promise<string>
    • Parameters

      • name: string
      • Optional isBlobUrl: boolean

      Returns Promise<string>

getValue: (<T>(name, defaultValue?) => Promise<T>)

Type declaration

    • <T>(name, defaultValue?): Promise<T>
    • Type Parameters

      • T

      Parameters

      • name: string
      • Optional defaultValue: T

      Returns Promise<T>

getValues: ((names) => Promise<GenericObject>) | ((namesWithDefaults) => Promise<GenericObject>)

Type declaration

Type declaration

Since

VM2.19.1

listValues: (() => Promise<string[]>)

Type declaration

    • (): Promise<string[]>
    • Returns Promise<string[]>

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

Type declaration

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

      Parameters

      • Rest ...args: any

      Returns void

notification: {
    (options): VMScriptGMNotificationControl;
    (text, title?, image?, onclick?): VMScriptGMNotificationControl;
}

Type declaration

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

Type declaration

    • (url, options?): 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.

      • Optional options: VMScriptGMTabOptions

      Returns VMScriptGMTabControl

    • (url, openInBackground?): VMScriptGMTabControl
    • 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.

      • Optional openInBackground: 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, onClick, options?) => string)

Type declaration

    • (caption, onClick, options?): 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) => void)

        Callback function when the command is clicked in the menu.

          • (event): void
          • Parameters

            • event: MouseEvent | KeyboardEvent

            Returns void

      • Optional options: {
            autoClose?: boolean;
            id?: string;
            title?: string;
        }

        Since

        VM2.15.9

        • Optional autoClose?: boolean

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

        • Optional id?: string

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

        • Optional title?: string

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

      Returns string

removeValueChangeListener: ((listenerId) => void)

Type declaration

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

      Parameters

      • listenerId: string

      Returns void

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

Type declaration

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

      Parameters

      • data: string

        The data to be copied to system clipboard.

      • Optional type: string

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

      Returns void

setValue: (<T>(name, value) => Promise<void>)

Type declaration

    • <T>(name, value): Promise<void>
    • Type Parameters

      • T

      Parameters

      • name: string
      • value: T

      Returns Promise<void>

setValues: ((values) => Promise<void>)

Type declaration

    • (values): Promise<void>
    • Parameters

      Returns Promise<void>

Since

VM2.19.1

unregisterMenuCommand: ((caption) => void)

Type declaration

    • (caption): 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>(details) => Promise<T> & VMScriptXHRControl)

Type declaration