Greasemonkey Manual:API: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
→Resources: greasemonkey-script: protocol |
No edit summary |
||
Line 20: | Line 20: | ||
; [[GM_getResourceURL]] : A function that loads an external resource via a URL, such as an image, and returns the string containing the base64 encoded in the <code>data:</code> URL scheme. As of [[Version_history#1.0_2|Greasemonkey 1.0]], this function returns <code>greasemonkey-script:</code> scheme URL. | ; [[GM_getResourceURL]] : A function that loads an external resource via a URL, such as an image, and returns the string containing the base64 encoded in the <code>data:</code> URL scheme. As of [[Version_history#1.0_2|Greasemonkey 1.0]], this function returns <code>greasemonkey-script:</code> scheme URL. | ||
=== | === Other === | ||
; [[GM_addStyle]] : A function, taking one parameter, a string of CSS to apply to the page. | ; [[GM_addStyle]] : A function, taking one parameter, a string of CSS to apply to the page. | ||
; [[GM_log]] : A function that accepts a parameter which will be routed to the Error Console, useful for examining values when writing a script. | ; [[GM_log]] : A function that accepts a parameter which will be routed to the Error Console, useful for examining values when writing a script. | ||
; [[GM_openInTab]] : Similar in spirit to <code>window.open()</code>, this function accepts a single parameter, the URL of a page to open in a new tab. | ; [[GM_openInTab]] : Similar in spirit to <code>window.open()</code>, this function accepts a single parameter, the URL of a page to open in a new tab. | ||
; [[GM_registerMenuCommand]] : An advanced function which allows a user script to register a menu item, and command to run when clicked, in the Firefox user interface. | ; [[GM_registerMenuCommand]] : An advanced function which allows a user script to register a menu item, and command to run when clicked, in the Firefox user interface. | ||
; [[GM_setClipboard]] : A function, taking one parameter, a string, sets the contents of the clipboard. | |||
; [[GM_xmlhttpRequest]] : A version of the XMLHttpRequest method underlying AJAX, this API call does '''not''' use the same-origin policy that a script running in a normal page is limited with, allowing complex mashups. | |||
; [[unsafeWindow]] : This object provides access to the raw JavaScript <code>window</code> scope of the content page. It is most commonly used to access JavaScript variables on the page. | |||
[[Category:API Reference|*{{FULLPAGENAME}}]] | [[Category:API Reference|*{{FULLPAGENAME}}]] |
Revision as of 15:30, 20 June 2013
Greasemonkey Manual |
Using Greasemonkey |
---|
Installing Scripts |
Monkey Menu |
Getting Help |
User Script Authoring |
Editing |
Environment |
API |
This section of the manual will be short and sweet. As mentioned elsewhere, Greasemonkey provides several methods in its API to enhance the power of user scripts. They are listed here, with a brief description, but each separate method has its own page with more in-depth information, please continue reading there!
Headers
- Metadata Block
- Through JavaScript comments Greasemonkey has metadata which gives information about the script and provides resources and functionality to scripts.
- GM_info
- Exposes this information, plus a bit more, to the user script.
Values
- GM_deleteValue
- This deletes a value from chrome that was previously set.
- GM_getValue
- A function intended to get stored values, see GM_setValue below.
- GM_listValues
- This API method retrieves an array of preference names that start with the branch's root.
- GM_setValue
- A function that accepts the name and value to store, persistently. This value can be retrieved later, even on a different invocation of the script, with GM_getValue.
Resources
- GM_getResourceText
- Like the previous, loads raw, plaintext from a resource.
- GM_getResourceURL
- A function that loads an external resource via a URL, such as an image, and returns the string containing the base64 encoded in the
data:
URL scheme. As of Greasemonkey 1.0, this function returnsgreasemonkey-script:
scheme URL.
Other
- GM_addStyle
- A function, taking one parameter, a string of CSS to apply to the page.
- GM_log
- A function that accepts a parameter which will be routed to the Error Console, useful for examining values when writing a script.
- GM_openInTab
- Similar in spirit to
window.open()
, this function accepts a single parameter, the URL of a page to open in a new tab. - GM_registerMenuCommand
- An advanced function which allows a user script to register a menu item, and command to run when clicked, in the Firefox user interface.
- GM_setClipboard
- A function, taking one parameter, a string, sets the contents of the clipboard.
- GM_xmlhttpRequest
- A version of the XMLHttpRequest method underlying AJAX, this API call does not use the same-origin policy that a script running in a normal page is limited with, allowing complex mashups.
- unsafeWindow
- This object provides access to the raw JavaScript
window
scope of the content page. It is most commonly used to access JavaScript variables on the page.