declare const unsafeWindow: Window; declare type VMScriptRunAt = | 'document-start' | 'document-body' | 'document-end' | 'document-idle'; /** Injection mode of a script. */ declare type VMScriptInjectInto = 'auto' | 'page' | 'content'; declare type GenericObject = Record; declare interface VMScriptGMInfoPlatform { arch: | 'aarch64' | 'arm' | 'arm64' | 'mips' | 'mips64' | 'ppc64' | 's390x' | 'sparc64' | 'x86-32' | 'x86-64'; browserName: 'chrome' | 'firefox' | string; browserVersion: string; /** * A copy of `navigator.userAgentData.getHighEntropyValues()` from the background script * of the extension, so it's not affected by devtools of the web page tab. * Only present in browsers that implement this API (Chromium >= 90). * @since VM2.27.0 */ fullVersionList?: { brand: string; version: string }[] | undefined; /** * A copy of `navigator.userAgentData.mobile` from the background script of the extension, * so it's not affected by devtools of the web page tab. * Only present in browsers that implement this API (Chromium >= 90). * @since VM2.27.0 */ mobile?: boolean | undefined; os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia'; } /** * GM_info.script and GM.info.script * Non-optional string property will be an empty string '' if omitted. */ declare interface VMScriptGMInfoScriptMeta { antifeature?: string[] | undefined; author?: string | undefined; compatible?: string[] | undefined; connect?: string[] | undefined; description: string; downloadURL?: string | undefined; excludeMatches: string[]; excludes: string[]; /** Empty is the same as `@grant none` */ grant: string[]; /** Use homepageURL instead */ homepage?: string | undefined; homepageURL?: string | undefined; icon?: string | undefined; includes: string[]; matches: string[]; /** User options and overrides for the script * @since VM2.31.1 */ options: { check_for_updates: boolean, inject_into: VMScriptInjectInto | null, noframes: boolean | null, override: { /** Keep the script's `@exclude` */ merge_excludes: boolean, /** Keep the script's `@include` */ merge_includes: boolean, /** Keep the script's `@match` */ merge_matches: boolean, /** Keep the script's `@exclude-match` */ merge_exclude_matches: boolean, /** User overridden `@exclude` */ use_excludes: string[], /** User overridden `@include` */ use_includes: string[], /** User overridden `@match` */ use_matches: string[], /** User overridden `@exclude-match` */ use_exclude_matches: string[], }, run_at: VMScriptRunAt | null, tags: string[], /** Last modification by the user; convertible as `new Date(user_modified)` */ user_modified: number, }, name: string; namespace: string; noframes?: boolean | undefined; require: string[]; resources: { name: string; url: string }[]; runAt: VMScriptRunAt | ''; supportURL?: string | undefined; unwrap?: boolean | undefined; updateURL?: string | undefined; version: string; } declare interface VMScriptGMInfoObject { /** A unique ID of the script. */ uuid: string; /** The injection mode of current script. See [`@inject-into`](https://violentmonkey.github.io/api/metadata-block/#inject-into) for more information. */ injectInto: VMScriptInjectInto; /** Contains structured fields from the [Metadata Block](https://violentmonkey.github.io/api/metadata-block/). */ script: VMScriptGMInfoScriptMeta; /** The meta block of the script. */ scriptMetaStr: string; /** Whether the script will be updated automatically. */ scriptWillUpdate: boolean; /** The name of userscript manager, which should be the string `Violentmonkey`. */ scriptHandler: string; /** Version of Violentmonkey. */ version: string; /** * True when this is an incognito profile (Chrome) or private mode (Firefox). * @since VM2.15.4 */ isIncognito: boolean; /** * Unlike `navigator.userAgent`, which can be overriden by other extensions/userscripts * or by devtools in device-emulation mode, `GM_info.platform` is more reliable as the * data is obtained in the background page of Violentmonkey using a specialized * extension API (`browser.runtime.getPlatformInfo` and `getBrowserInfo`). */ platform: VMScriptGMInfoPlatform; /** * A safe copy of `navigator.userAgent` from the content script of the extension, * so it cannot be overridden by other extensions/userscripts, but unlike * `GM_info.platform` it can be customized in devtools “device emulation” or * “network conditions” for this tab. * @since VM2.20.2 */ userAgent: string; /** * A safe copy of `navigator.userAgentData` from the content script of the extension, * so it cannot be overridden by other extensions/userscripts, but unlike * `GM_info.platform` it can be customized in devtools "device emulation" or * "network conditions" for this tab. * * Only present if the browser actually implements it * ([currently](https://caniuse.com/mdn-api_navigator_useragentdata) Chromium-based 90+), * because there's no reliable/official polyfill. * * Violentmonkey implements the [official API](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData), * including [getHighEntropyValues](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues) * function to obtain the extra info asynchronously. * * @since VM2.20.2 */ userAgentData?: | { brands: { brand: string; version: string }[]; mobile: boolean; platform: string; getHighEntropyValues(hints: string[]): Promise; } | undefined; } /** * An object that exposes information about the current userscript. */ declare const GM_info: VMScriptGMInfoObject; /** The original console.log */ declare function GM_log(...args: any): void; /** Retrieves a value for current script from storage. */ declare function GM_getValue(name: string, defaultValue?: T | undefined): T; /** @since VM2.19.1 */ declare function GM_getValues(names: string[]): GenericObject; /** @since VM2.19.1 */ declare function GM_getValues(namesWithDefaults: GenericObject): GenericObject; /** Sets a key / value pair for current script to storage. */ declare function GM_setValue(name: string, value: T): void; /** @since VM2.19.1 */ declare function GM_setValues(values: GenericObject): void; /** Deletes an existing key / value pair for current script from storage. */ declare function GM_deleteValue(name: string): void; /** @since VM2.19.1 */ declare function GM_deleteValues(names: string[]): void; /** Returns an array of keys of all available values within this script. */ declare function GM_listValues(): string[]; declare type VMScriptGMValueChangeCallback = ( /** The name of the observed variable */ name: string, /** The old value of the observed variable (`undefined` if it was created) */ oldValue: T, /** The new value of the observed variable (`undefined` if it was deleted) */ newValue: T, /** `true` if modified by the userscript instance of another tab or `false` for this script instance. Can be used by scripts of different browser tabs to communicate with each other. */ remote: boolean, ) => void; /** Adds a change listener to the storage and returns the listener ID. */ declare function GM_addValueChangeListener( name: string, callback: VMScriptGMValueChangeCallback, ): string; /** Removes a change listener by its ID. */ declare function GM_removeValueChangeListener(listenerId: string): void; /** Retrieves a text resource from the *Metadata Block*. */ declare function GM_getResourceText( /** Name of a resource defined in the *Metadata Block*. */ name: string, ): string; /** * Retrieves a `blob:` or `data:` URL of a resource from the *Metadata Block*. * * Note: when setting this URL as `src` or `href` of a DOM element, it may fail on some sites with a particularly strict CSP that forbids `blob:` or `data:` URLs. Such sites are rare though. The workaround in Chrome is to use `GM_addElement`, whereas in Firefox you'll have to disable CSP either globally via `about:config` or by using an additional extension that modifies HTTP headers selectively. */ declare function GM_getResourceURL( /** Name of a resource defined in the *Metadata Block*. */ name: string, /** * - If `true`, returns a `blob:` URL. It's short and cacheable, so it's good for reusing in multiple DOM elements. * - If `false`, returns a `data:` URL. It's long so reusing it in DOM may be less performant due to the lack of caching, but it's particularly handy for direct synchronous decoding of the data on sites that forbid fetching `blob:` in their CSP. */ isBlobUrl?: boolean | undefined, ): string; /** * Appends and returns an element with the specified attributes. * * Examples: * * ```js * // 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 }); * ``` */ declare function GM_addElement( /** 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. */ tagName: 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. */ attributes?: Record | undefined, ): HTMLElement; declare function GM_addElement( /** * 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` (``) for `script`, `link`, `style`, `meta` tags. * - `document.body` (``) for other tags or when there's no ``. * - `document.documentElement` (`` or an XML root node) otherwise. */ parentNode: HTMLElement, /** 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. */ tagName: 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. */ attributes?: Record | undefined, ): HTMLElement; /** Appends and returns a `