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 });
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.
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 });
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.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.
Appends and returns a <style> element with the specified CSS.
Adds a change listener to the storage and returns the listener ID.
Retrieves a text resource from the Metadata Block.
Name of a resource defined in the Metadata Block.
The original console.log
Shows an HTML5 desktop notification.
Shows an HTML5 desktop notification.
Main text of the notification.
Optionaltitle: stringTitle of the notification.
Optionalimage: stringURL of an image to show in the notification.
Optionalonclick: () => voidCallback when the notification is clicked by user.
Opens URL in a new tab.
The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs.
Optionaloptions: VMScriptGMTabOptionsOpens URL in a new tab.
The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs.
OptionalopenInBackground: booleanOpen the tab in background. Note, this is a reverse of the first usage method so for example true is the same as { active: false }.
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.
The name to show in the popup menu.
Callback function when the command is clicked in the menu.
Optionaloptions: { autoClose?: boolean; id?: string; title?: string }OptionalautoClose?: booleanDefault: true.
Whether to auto-close the popup after the user invoked the command.
Optionalid?: stringDefault: the caption parameter.
In 2.15.9-2.16.1 the default was a randomly generated string.
Optionaltitle?: stringA hint shown in the status bar when hovering the command.
Removes a change listener by its ID.
Sets data to system clipboard.
The data to be copied to system clipboard.
Optionaltype: stringThe MIME type of data to copy. Default as text/plain.
Unregisters a command which has been registered to Violentmonkey popup menu.
The name of command to unregister.
The Greasemonkey4 API, https://wiki.greasespot.net/Greasemonkey_Manual:API