Google Chrome GM_* (greasemonkey functions) emulation

By Vladimir Alexiev Last update Feb 10, 2010 — Installed 10,666 times.

Script Summary: Google Chrome can install userscripts natively, but scripts that use GM_* functions don't work. This script emulates the following functions, allowing you to use MORE userscripts in Chrome: GM_setValue, GM_getValue, GM_deleteValue, GM_registerMenuCommand, GM_xmlhttpRequest, GM_addStyle. They are restricted to the same domain (the Greasemonkey functions have no cross domain restrictions), but it's better than nothing.



Google Chrome can install userscripts natively. (There is the Greasemetal extension, but it didn't work for me)
However, scripts that use GM_* functions don't work, see Chrome bugs 16341 and 4476
This script provides the following functions, allowing you to use MANY MORE userscripts in Chrome:

GM_setValue(key,value)
Stores the variable value as a cookie so it can be retrieved later. With Greasemonkey, these would be available to the script no matter what site it is being used on. With this script, it is available only for the current domain (as with normal cookies). Unlike Greasemonkey, which can store only numbers, strings and boolean values, this script can store regular expressions, dates, functions, arrays and objects as well (it utilises my toRecoverableString function).
GM_getValue(key[,defaultValue])
Returns the previously stored variable using the given key. If none, it returns the defaultValue, or undefined if no defaultValue is provided.
GM_deleteValue(key)
Deletes the stored value - this is not a normal Greasemonkey function, but it just seemed sensible to provide a way to delete them again...
GM_registerMenuCommand(title,function)
Adds a menu item with the specified title that runs the specified function when clicked. Unlike Greasemonkey (which uses the browser's own menu), this script places a menu in the top right corner of the page when needed - it is even keyboard accessible, using spatial navigation.
GM_xmlhttpRequest(details)
Performs an XMLHttpRequest using the XMLHttpRequest constructor. Restricted to the same domain (the Greasemonkey function has no cross domain restrictions), but it's better than nothing
GM_addStyle(CSSString)
Adds a stylesheet LINK tag to the document containing the new CSS. Note that this can cause problems with sites using jQuery, or stylesheet switching scripts.
Additionally, it maps window._content to window, as this is unnecessarily used by many Greasemonkey scripts.

Adapted from aagmfunctions.js by TarquinWJ, version 1.3.1 (more details)