Post Reply
User avatar
Site Admin
Posts: 2383
Joined: 20.01.06 02:16:15


Post by derjanb » 04.05.11 10:00:35


The unsafeWindow object provides full access to the pages javascript functions and variables.


Chrome/Chromium does not have native DOMAttrModified support, but in TM statements like

Code: Select all

var foo = document.getElementById('whatever');
foo.addEventListener("DOMAttrModified", function (e) {console.log(e); }), false);
are working as usual for any attribute change of "foo".
Event handlers that catch bubbled events like this:

Code: Select all

document.addEventListener("DOMAttrModified", function (e) {console.log(e); }), false);
are working too, but will only be notified of changes of objects that are "registered" for DOMAttrModified like the element "foo" is.[/t][/i]


Although this is not needed in Chrome/Chromium some scripts need that object to be part of HTML elements to run successfully. That's why TM adds this property to every HTMLElement to return the (never wrapped) element.


Adds the given style to the document.


Deletes 'name' from storage.


List all names of the storage.

GM_addValueChangeListener(name, function(name, old_value, new_value, remote) {}) needs build nr. 2602 or greater

Adds a change listener to the storage and returns the listener ID.
'name' is the name of the observed variable.
The 'remote' argument of the callback function shows whether this value was modified from the instance of another tab (true) or within this script instance (false).
Therefore this functionality can be used by scripts of different browser tabs to communicate with each other.

GM_removeValueChangeListener(listener_id) needs build nr. 2602 or greater

Removes a change listener by its ID.

GM_setValue(name, value)

Set the value of 'name' to the storage.

GM_getValue(name, defaultValue)

Get the value of 'name' from storage.


Log a message to the console.


Get the content of a predefined @resource tag at the script header.


Get the base64 encoded URI of a predefined @resource tag at the script header.

GM_registerMenuCommand(name, fn)

Register a menu to be displayed at the Tampermonkey menu at pages where this script runs.

GM_openInTab(url, options)

Open a new tab with this url. The options object can have two properties: 'active' decides whether the new tab should be focused and 'insert' that inserts the new tab after the current one. Otherwise the new tab is just appended.


Make an xmlhttpRequest. Supports:
- cross domain requests
- headers (user-agent, referer, ...) needs build nr. 2656 or greater
- Note: the synchronous flag at the details is not supported


Get a object that is persistent as long as this tab is open.


Save the tab object to reopen it after a page unload.


Get all tab objects in an array to communicate with other scrips instances.

GM_notification(msg, title, callback, delay)

Shows a notification that will be hidden after delay ms (0 = disabled) and the callback is called in case the user clicks the notification.


Returns the Tampermonkey version string.

GM_installScript(url, callback)

Install a userscript to Tampermonkey. The callback gets an object like "{ found: true, installed: true }" that shows whether the script was found and the user installed it.


Get some info about the script and TM. The object might look like this:

Code: Select all

---> script: Object+
------> author: ""
------>copyright: "2012+, You"
------>description: "enter something useful"
------>excludes: Array[0]
------>homepage: null
------>icon: null
------>icon64: null
------>includes: Array[2]
------>lastUpdated: 1338465932430
------>matches: Array[2]
------>name: "Local File Test"
------>namespace: "http://use.i.E.your.homepage/"
------>options: Object+
--------->awareOfChrome: true
--------->compat_arrayleft: false
--------->compat_foreach: false
--------->compat_forvarin: false
--------->compat_metadata: false
--------->compat_prototypes: false
--------->compat_uW_gmonkey: false
--------->noframes: false
--------->override: Object+
------------>excludes: false
------------>includes: false
------------>orig_excludes: Array[0]
------------>orig_includes: Array[2]
------------>use_excludes: Array[0]
------------>use_includes: Array[0]
--------->run_at: "document-end"
------>position: 1
------>resources: Array[0]
------>run-at: "document-end"
------>system: false
------>unwrap: false
------>version: "0.1"
---> scriptMetaStr: undefined
---> scriptSource: "// ==UserScript==↵// @name       Local File Test↵// ....↵"
---> scriptUpdateURL: undefined
---> scriptWillUpdate: false
---> scriptHandler: "Tampermonkey"
---> version: "2.4.2716"


Tampermonkey supports this way of storing meta data. TM tries to automatically detect whether a script needs this option to be enabled.

for each (var k in arr)

Tampermonkey replaces "for each" statements by chrome compatible code. TM tries to automatically detect whether a script needs this option to be enabled.
ImageIf you like what I'm doing, please consider a donation here. Image

Post Reply