Greasemonkey Manual:API: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Aavindraa (talk | contribs)
api definition
GM.registerMenuCommand
 
(64 intermediate revisions by 28 users not shown)
Line 1: Line 1:
__NOTOC__
{{Greasemonkey Manual TOC}}
{{Greasemonkey Manual TOC}}
== What is an API? ==
An API, or application programming interface, provides a framework, or set of commonly used functions or methods in a program, or in this case, [[Greasemonkey]].
== The APIs ==


This section of the manual will be short and sweet.
This section of the manual will be short and sweet.
As mentioned elsewhere, [[Greasemonkey]] provides APIs to enhance the power of [[user script]]s.
As mentioned elsewhere, [[Greasemonkey]] provides several methods in its API to enhance the power of [[user script]]s.
They will be listed here, with a brief description, but each separate API call has its own page with more in-depth information, please continue reading there!
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!


; [[GM_addStyle]] : A function, taking one parameter, a string of CSS to apply to the page.
=== Headers ===
; [[GM_getValue]] : A function intended to get stored values, see [[GM_setValue]] below.
; [[Metadata Block|Metadata Block]] : Information about the script such as its name or version is encoded into comments by the script author.
; [[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]].
; [[GM.info]] : Exposes this information (plus a bit more) to the user 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_registerMenuCommand]] : An advanced function which allows a user script to register a menu item, and command to run when clicked, in the Firefox UI.
; [[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.
; [[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.
; [[GM_getResourceText]] : Like the previous, loads text from a resource.


=== Values ===
; [[GM.deleteValue]] : Deletes a value from chrome that was previously set.
; [[GM.getValue]] : Retrieves stored values, see [[GM.setValue]] below.
; [[GM.listValues]] : Retrieves an array of stored values' keys.
; [[GM.setValue]] : Permanently stores a value under a key, later available via [[GM.getValue]].


=== Resources ===
; [[GM.getResourceUrl]] : Provides a URL for loading a <code>@resource</code>, such as an image, into the page.


== Notes ==
=== Other ===
All GM_* functions were blocked in version 0.3.5, due to security vulnerabilities.
; [[GM.notification]] : Opens a notification dialog.
These functions were restored with updates making them secure, and the new [[unsafeWindow]] object was added, in version 0.5.
; [[GM.openInTab]] : Opens a given URL in a new tab.
; [[GM.registerMenuCommand]] : Adds an item to the "User Script Commands" section of the [[Monkey Menu]].
; [[GM.setClipboard]] : Sets the contents of the clipboard.
; [[GM.xmlHttpRequest]] : A variant of XMLHttpRequest, this method allows skipping use the same-origin policy, enabling 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|*]]
[[Category:API Reference|*{{FULLPAGENAME}}]]

Latest revision as of 01:12, 28 January 2021


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
Information about the script such as its name or version is encoded into comments by the script author.
GM.info
Exposes this information (plus a bit more) to the user script.

Values

GM.deleteValue
Deletes a value from chrome that was previously set.
GM.getValue
Retrieves stored values, see GM.setValue below.
GM.listValues
Retrieves an array of stored values' keys.
GM.setValue
Permanently stores a value under a key, later available via GM.getValue.

Resources

GM.getResourceUrl
Provides a URL for loading a @resource, such as an image, into the page.

Other

GM.notification
Opens a notification dialog.
GM.openInTab
Opens a given URL in a new tab.
GM.registerMenuCommand
Adds an item to the "User Script Commands" section of the Monkey Menu.
GM.setClipboard
Sets the contents of the clipboard.
GM.xmlHttpRequest
A variant of XMLHttpRequest, this method allows skipping use the same-origin policy, enabling 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.