|
|
Line 1: |
Line 1: |
| == Description == | | == Description == |
|
| |
|
| The '''metadata block''' is a section of a [[user script]] that does not execute any code, but describes the script. It contains the script name, namespace, description, and [[include and exclude rules]]. | | The '''metadata block''' is a section of a [[user script]] that describes the script. |
| | It usually contains the script name, namespace, description, and [[include and exclude rules]]. |
| | The metadata block appears in JavaScript line comments and may appear anywhere in the top level Greasemonkey code scope of the script, but is usually near the top of the file. |
|
| |
|
| The metadata block appears in JavaScript comments and may appear anywhere in the top level Greasemonkey code scope of the script, but is usually near the top of the file. It begins with the line
| | If the metadata block includes a key that Greasemonkey does not understand, it will simply be ignored. |
| | Some authors choose to include their own keys, and [http://userscripts.org userscripts.org] defines a set of metadata keys for varying purposes. |
|
| |
|
| <pre class='sample'>// ==UserScript==</pre>
| | It is important to note that all of the information specified in the metadata block is parsed and loaded at install time only. |
| | | Although script authors may edit the ''source'' of a user script on the fly, and see these changes reflected upon the next execution of the script, metadata is ''not'' reloaded upon every execution. |
| and ends with
| | To change the metadata Greasemonkey uses, the script must be reinstalled. |
| | |
| <pre class='sample'>// ==/UserScript==</pre>
| |
| | |
| Everything between those lines is in the format
| |
| | |
| <pre class='sample'>// @key value</pre>
| |
| | |
| If the metadata block includes a key that Greasemonkey does not understand, it will simply be ignored. Key names are typically constructed from alphanumeric characters. User script hosting sites may utilize a XML styled name prefix to identify the origin of the key. An example of this is ''prefix:key''.
| |
|
| |
|
| == Syntax == | | == Syntax == |
| '''// ==UserScript=='''
| |
|
| |
|
| '''// == @'''''key'' '''value'''
| | The metadata block must follow the format: |
|
| |
|
| '''// ==/UserScript==''' | | <pre class='sample'> |
| | | // ==UserScript== |
| :Value: Object
| | // @key value |
| :Compatibility: [[Version_history#0.2.5|Greasemonkey 0.2.5+]]
| | // ==/UserScript== |
| | | </pre> |
| :{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
| |
| |+ Keys
| |
| ! colspan="4" style="background:#CC9900;"|'''Properties'''
| |
| |-
| |
| | <code><span style="background:#FFFFE0;">[[#.40name |@name]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40include |@include]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40resource |@resource]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40unwrap |@unwrap]]</span></code>
| |
| |-
| |
| |<code><span style="background:#FFFFE0;">[[#.40namespace |@namespace]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40exclude |@exclude]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40require |@require]]</span></code>
| |
| |-
| |
| |<code><span style="background:#FFFFE0;">[[#.40description |@description]]</span></code>
| |
| |}
| |
| :* All properties are optional
| |
| | |
| === Properties ===
| |
| ----
| |
|
| |
|
| ==== @name ====
| | It must use line comments (<code>//</code>) like above, not block comments (<code>/* */</code>). |
| | Some keys may have multiple values. |
| | In all cases the key and value(s) are separated by whitespace. |
|
| |
|
| :Value: String
| | === @name === |
| :Usage: <code>// @'''name''' My Script</code>
| |
| ::* The name of the script. This appears in the [[Greasemonkey_Manual:Manage_Dialog|script manager]] and [[Greasemonkey_Manual:Monkey_Menu |monkey menu]], and is also used to determine whether to overwrite an old version of a script or to install it separately. If no name is provided, it will be inferred from the file name.
| |
| ::* If the file name or the @name key exceeds 24 characters the file name will be truncated during installation not including spaces and other special characters. As of [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0]], new scripts will be stored under their own folder name in the [[Scripts directory|gm_scripts folder]] and also include spaces to underscores conversion and other special characters. The [[Scripts directory|scripts directory]] is also backed up into a folder called gm_scripts_08bak when migrating to version [[Version_history#0.8.20080609.0|0.8.0]].
| |
|
| |
|
| | Example: |
| | // @name Example Script |
|
| |
|
| ==== @namespace ====
| | The name of the script. |
| | This appears in the [[Greasemonkey_Manual:Manage_Dialog|script manager]] and [[Greasemonkey_Manual:Monkey_Menu|monkey menu]], and is also the unique identifer of a script (within a [[#@namespace]]). |
| | If no name is provided, it will be derived from the file name. |
|
| |
|
| :Value: String
| | === @namespace === |
| :Usage: <code>// @'''namespace''' <nowiki>http://www.example.com/gmscripts</nowiki></code>
| |
| ::* The namespace, along with the name, is used to determine whether to overwrite an old version of a script or to install it separately. A script author will usually put all of their scripts under one common namespace, and then assign each script a unique name. If two scripts have the same name, but a different namespace, they can co-exist. However, two scripts of the same name in the same namespace are assumed to be replacements for one another and one will be overwritten by the other.
| |
| ::* While the namespace is '''non-semantic''', it should be your prefered internet homepage [http://labs.apache.org/webarch/uri/rfc/rfc3986.html URI] according to the [http://www.w3.org/Addressing W3C standards specification]. If no namespace is provided, it is assumed to be the domain from which the script is installed. Since a script can live on various servers or on a local file system, authors may choose to omit this key when publishing on [http://userscript.org userscripts.org] and let Greasemonkey supply one automatically. If you are creating one locally, authors may choose the [http://labs.apache.org/webarch/uri/rfc/rfc3986.html URI specification] standard of <code>http://localhost</code> for the value as being an anonymous local script.
| |
|
| |
|
| ::* Common String Values | | Example: |
| :::* '''Greasemonkey addon supplied'''
| | <nowiki>// @namespace http://www.example.com/gmscripts</nowiki> |
| ::::Usage: Omitted [[#.40namespace |@namespace]] in source userscript file
| |
| ::::Examples:
| |
| ::::{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
| |
| |+ ''Automatic host to namespace mapping''
| |
| !style="background:#CC9900;"|'''Script Host''' || style="background:#CC9900;"|'''Chosen Namespace'''
| |
| |-
| |
| |<code><span style="background:#FFFFE0;">http://userscripts.org/scripts/source/''scriptid''.user.js</span></code> || <code><span style="background:#FFFFE0;">userscripts.org</span></code>
| |
| |-
| |
| |<code><span style="background:#FFFFE0;">http://example.org/scripts/filename.user.js</span></code> || <code><span style="background:#FFFFE0;">example.org</span></code>
| |
| |-
| |
| |<code><span style="background:#FFFFE0;">http://localhost/scripts/filename.user.js</span></code> || <code><span style="background:#FFFFE0;">localhost</span></code>
| |
| |-
| |
| |}
| |
|
| |
|
| :::* '''tag URI'''
| | The combination of namespace and name is the unique identifier for a Greasemonkey script. |
| ::::Usage: "tag:" taggingEntity ":" specific [ "#" fragment ]
| | If a script is being installed, and a script what that same name '''and''' namespace already exists, it will be replaced by the new script. |
| ::::* If a date/time stamp field is omitted, it is assumed to be first item ''(e.g. 2005 becomes 2005-01-01T00:00:00Z)
| | Otherwise, the new script is added to the set of installed scripts. |
| ::::Examples:
| | A script author will usually put all of their scripts under one common namespace, and then assign each script a unique name. |
| :::::<code>'''@namespace''' <nowiki>tag:johndoe@example.com,2009:johndoe</nowiki></code>
| |
| :::::<code>'''@namespace''' <nowiki>tag:johndoe@example.net,2010-05:johndoe/pathto</nowiki></code>
| |
| :::::<code>'''@namespace''' tag:userscripts.org,2005-06-19T23:33:49Z:JohnDoe:DescriptionWithNoSpaces:etc:etc:etc</code>
| |
| ::::See Also: http://www.faqs.org/rfcs/rfc4151.html
| |
|
| |
|
| :::* '''userscripts.org''' ''(User contributed)''
| | While the namespace is non-semantic, a URL is often used. |
| ::::Usage: id [[ " + " id ], [ " + " id ], ...]
| | Some authors use the common home page for the collection of scripts they have written. |
| ::::* An id consists of either a full name, userid or vanityid.
| | But remember, the namespace can be any unique value. |
| ::::* Multiple contributor attribution may be notated here by appending the plus symbol and the next id.
| |
| ::::Examples:
| |
| :::::<code>'''@namespace''' anotherjesse</code>
| |
| :::::<code>'''@namespace''' ''userid'' + ''vanityid'' + ''Firstname'' ''Lastname''</code>
| |
|
| |
|
| :::* '''XML URI'''
| | === @description === |
| ::::Usage: scheme "://" domain [ "." tld ][ "/" pathto ]
| |
| ::::Examples:
| |
| :::::<code>'''@namespace''' http://localhost</code>
| |
| :::::<code>'''@namespace''' http://localhost.localdomain</code>
| |
| :::::<code>'''@namespace''' http://userscripts.org/users/''userid''</code>
| |
| :::::<code>'''@namespace''' http://example.org/pathto/script</code>
| |
| ::::See Also: https://developer.mozilla.org/en/Namespaces
| |
|
| |
|
| ::* The [https://addons.mozilla.org/firefox/addon/722 NoScript] add-on currently utilizes namespace filtering, and may sanitize user scripts that are not listed in the XSS white-list section of the options dialog. | | Example: |
| | // @description This script even does the laundry! |
|
| |
|
| | Just a brief summary of what the script does, presented to the user as the script is installed, and in the manage dialog. |
|
| |
|
| | === @include === |
|
| |
|
| ==== @description ====
| | Examples: |
| :Value: String | | <nowiki>// @include http://www.example.com/*</nowiki> |
| :Usage: <code>// @'''description''' This script even does the laundry!</code>
| | <nowiki>// @include http://*</nowiki> |
| ::* Just a brief summary of what the script does, to present to the user who is installing it.
| | <nowiki>// @include *</nowiki> |
|
| |
|
| | See [[Include and exclude rules]]. |
| | There can be any number of @include rules in a script. |
|
| |
|
| | === @exclude === |
|
| |
|
| ==== @include ====
| | Examples: see @include above |
| :Value: String
| |
| :Usage: <code>// @'''include''' <nowiki>http://www.example.com/*</nowiki></code>
| |
| ::* Refer to ''[[Include and exclude rules]]''. There can be any number of @include rules in a script.
| |
| ::* You cannot edit a live scripts @include and have it take effect.
| |
|
| |
|
| | See [[Include and exclude rules]]. |
| | There can be any number of @exclude rules in a script. |
|
| |
|
| ==== @exclude ====
| | === @resource === |
| :Value: String
| |
| :Usage: <code>// @'''exclude''' <nowiki>http://www.example.com/foo/*</nowiki></code>
| |
| ::* Refer to ''[[Include and exclude rules]]''. There can be any number of @exclude rules in a script.
| |
| ::* You cannot edit a live scripts @exclude and have it take effect.
| |
|
| |
|
|
| |
| ==== @resource ====
| |
| :Value: String
| |
| :Compatibility: [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0+]] | | :Compatibility: [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0+]] |
| :Usage: <code>// @'''resource''' resourceName <nowiki>http://www.example.com/resource.png</nowiki></code>
| |
| ::* There can be any number of @resource keys in a script.
| |
| ::* While the resourceName is non-semantic, it is suggested that it should be compatible with JavaScript variable naming conventions and XML/CSS naming conventions to help keep things consistent.
| |
| ::* Each resourceName must have a unique name.
| |
| ::* This metadata block key property may be used to cache a local or remote resource into the current user script at installation time. Greasemonkey will not redownload these external dependencies every time the script is executed on a web page specified by [[#.40include |@include]].
| |
| ::* Resources may include the scheme of file, http, https or ftp. If no scheme is provided, it is assumed to be the domain from which the script is installed including the full path. They may be accessed through [[GM_getResourceText]] and [[GM_getResourceURL]] respectively.
| |
|
| |
|
| |
|
| |
|
| ==== @require ====
| | Example: |
| | <nowiki>// @resource resourceName http://www.example.com/example.png</nowiki> |
| | |
| | There can be any number of @resource keys in a script. |
|
| |
|
| :Value: String
| | While the resourceName is non-semantic, it should comply with JavaScript identifier restrictions. |
| :Compatibility: [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0+]]
| | Each @resource must have a unique name. |
| :Usage: <code>// @'''require''' foo.js</code>
| |
| ::* There can be any number of @require keys in a script.
| |
| ::* This metadata block key property may be used to cache a local or remote script into the current user script at installation time. Greasemonkey will not redownload these external dependencies every time the script is executed on a web page specified by [[#.40include |@include]].
| |
| ::* As with all metadata values that are stored in [[Config.xml |config.xml]], these are read at install time only. Adding or removing @require entries will have no effect. The script must be reinstalled or the [[Config.xml |config.xml]] will need to be modified manually.
| |
| ::* Script sources may include the scheme of file, http, https or ftp. If no scheme is provided, it is assumed to be the domain from which the script is installed including the full path.
| |
| :::* Some common JavaScript libraries may be obtained from the [http://code.google.com/apis/ajaxlibs/documentation/ Google AJAX Libraries API] or [http://developer.yahoo.com/yui/articles/hosting/ YUI]).
| |
|
| |
|
| | Each @resource is downloaded once, when the script is installed, and stored on the user's hard drive alongside the script. |
| | The URL specified may be relative to the URL the script is being installed from. |
|
| |
|
| | These named resources may be accessed through [[GM_getResourceText]] and [[GM_getResourceURL]] respectively. |
|
| |
|
| ==== @unwrap ====
| | === @require === |
|
| |
|
| :Value: undefined
| | Compatibility: [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0+]] |
| :Compatibility: [[Version_history#0.8.20090123.1|Greasemonkey 0.8.1+]]
| |
| :Usage: <code>// @'''unwrap'''</code>
| |
| ::* Also referenced as a metadata imperative. This metadata block key property must not include any value after it or it may be ignored altogether.
| |
| ::* Removes the anonymous function wrapper around scripts.
| |
| :::* '''This key is strongly recommended to only be used for [[Global_object#Debugging|debugging]] purposes.'''
| |
| :::* By default most versions of Greasemonkey automatically encapsulate each script in an anonymous function wrapper. In other words:
| |
| ::::* <code>(function(){ /* script source */ })();</code>
| |
| :::* Encapsulation of the script prevents name collisions of variables and objects used by [[XPCNativeWrapper]] and other objects typically inserted by the browser. If an unwrapped user script uses a reserved object name incorrectly, it will throw an error and script execution will most likely fail. One of the simplest ways to confirm this is to include '''@unwrap''' and have a script with a simple variable declaration of <code>var sidebar = "foo";</code>. This will return a script error of Illegal value, and script execution will cease. See also [http://greasemonkey.devjavu.com/ticket/108 #108].
| |
|
| |
|
| | Example: |
| | <nowiki>// @require http://www.example.com/example.js</nowiki> |
| | |
| | There can be any number of @require keys in a script. |
| | Each @require is downloaded once, when the script is installed, and stored on the user's hard drive alongside the script. |
| | The URL specified may be relative to the URL the script is being installed from. |
|
| |
|
| | === @unwrap === |
|
| |
|
| == Other Keys ==
| | Compatibility: [[Version_history#0.8.20090123.1|Greasemonkey 0.8.1+]] |
|
| |
|
| Some [[user script]]s contain other special keys in the metadata block.
| | Example: |
| | // @unwrap |
| | |
| | This declarative key has no associated value. |
| | It changes the interpretation of the script as it executes. |
|
| |
|
| '''These unsupported metadata keys serve no technical purpose and are ignored by the [[Greasemonkey|Greasemonkey extension]], but can be read by human beings or utilized by other code.'''
| | Normally, greasemonkey scripts are wrapped in an anonymous function when they are executed. |
| | This behavior started in very early versions of greasemonkey, which ran scripts directly in the content page, to separate their variables from those in the page. |
| | In later versions, it remains because isolating the script from the [[sandbox]] scope still helps in certain cases. |
|
| |
|
| :{| cellpadding="5" style="border-style:solid; background-color:#FFFFFF;"
| | This key is strongly recommended to only be used for [[Global_object#Debugging|debugging]] purposes. |
| |+ Keys
| |
| ! colspan="4" style="color: #FFFFFF; background-color:#000000;"|'''Properties'''
| |
| |-
| |
| | colspan="3" style="text-align: center; color: #FFFFFF; background-color:#FF8800;"|'''userscripts.org'''
| |
| | colspan="1" style="text-align: center; color: #FFFFFF; background-color:#FF8800;"|'''user contributed'''
| |
| |-
| |
| |<code><span style="background-color:#FFFFFF;">[[#.40copyright |@copyright]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:script |@uso:script]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:rating |@uso:rating]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40attribution |@attribution]]</span></code>
| |
| |-
| |
| |<code><span style="background-color:#FFFFFF;">[[#.40license |@license]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:version |@uso:version]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:installs |@uso:installs]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40contributor |@contributor]]</span></code>
| |
| |-
| |
| |<code><span style="background-color:#FFFFFF;">[[#.40version |@version]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:timestamp |@uso:timestamp]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:reviews |@uso:reviews]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40author |@author]]</span></code>
| |
| |-
| |
| | || <code><span style="background-color:#FFFFFF;">[[#.40uso:hash |@uso:hash]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40uso:discussions |@uso:discussions]]</span></code> || <code><span style="background-color:#FFFFFF;">[[#.40homepage |@homepage]]</span></code>
| |
| |-
| |
| | || || <code><span style="background-color:#FFFFFF;">[[#.40uso:fans |@uso:fans]]</span></code>
| |
| |}
| |
| :* This is by no means an exhaustive list, nor is it meant to be.
| |
| ===== @copyright =====
| |
| | |
| :Value: String
| |
| :Usage: <code>// @'''copyright''' Year, Author (Author Homepage)</code>
| |
| ::* It is '''strongly recommended''' to use this key to identify a scripts copyright author and homepage. Usually a script repository such as [http://userscripts.org userscripts.org] will be able to identify and track copyright via the ''userid'', versions and diffs but it is still suggested to include this for copyright verification purposes.
| |
| ::* Example:
| |
| ::: <code>// @copyright 2009+, John Doe (<nowiki>http://www.example.com/projecthomepage</nowiki>)</code>
| |
| | |
| ===== @licence =====
| |
| | |
| :Value: String
| |
| :Usage: <code>// @'''license''' License Type; License Homepage</code>
| |
| ::* There can be any number of @license keys in a script for multiple licensing however userscripts.org will only display the first occurrence as the primary.
| |
| ::* It is '''strongly recommended''' to use this key to describe who can use, copy, modify and distribute a script.
| |
| ::* A list of common open-source license can be found at [http://www.opensource.org/licenses opensource.org].
| |
| ::* In order to make an assertion on control of distribution of a script, it is important to keep in mind the following definitions:<dl><dt>Code ''(or module)'' licenses<dd>These are typically for all code including binaries, scripts, HTML and CSS.<dt>Content licenses<dd>These are typically documents such as guides, wikis and images. The [http://en.wikipedia.org/wiki/Data:_URI_scheme data:image URI scheme] is considered content.</dl>
| |
| ::* Example: ''(GPL is a Code License and CC is a Content License)''
| |
| ::: <code>// @license GPL version 3 or any later version; <nowiki>http://www.gnu.org/copyleft/gpl.html</nowiki></code>
| |
| ::: <code>// @license (CC) Attribution Non-Commercial Share Alike; <nowiki>http://creativecommons.org/licenses/by-nc-sa/3.0/</nowiki></code>
| |
| | |
| ===== @version =====
| |
| | |
| :Value: String or Number
| |
| :Usage: <code>// @'''version''' 0.0.1</code>
| |
| ::* Typically this is in the industry standard form of major dot minor dot build
| |
| ::* This key can also be used in some scripts that are self-updating. Usually, this will include a time stamp indicating the number of milliseconds that have expired since 1 January 1970 00:00:00 UCT, which can be generated by calling <code>new Date().getTime()</code>.
| |
| | |
| ===== @uso:script =====
| |
| | |
| :Value: String or Number
| |
| :Usage: <code>// @'''uso:script''' ''scriptid'' </code>
| |
| ::* userscripts.org will dynamically create an ascending numerical value based on the next available script id in the repository.
| |
| :: '''NOTE:''' It is not necessary to define this key in a script as the meta.js routine will automatically return this key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| ===== @uso:version =====
| |
| | |
| :Value: String or Number
| |
| :Usage: <code>// @'''uso:version''' ''versionid'' </code>
| |
| ::* userscripts.org will dynamically create an ascending numerical value based on the next available version id in the repository.
| |
| :: '''NOTE:''' It is not necessary to define this key in a script as the meta.js routine will automatically return this key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| ===== @uso:timestamp =====
| |
| :Value: String
| |
| :Usage: <code>// @'''uso:timestamp''' Wed, 17 Jun 2009 22:50:26 +0000 </code>
| |
| ::* userscripts.org will return the last modified date of the current user script.
| |
| :: '''NOTE:''' It is not necessary to define this key in a script as the meta.js routine will automatically return this key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| ===== @uso:hash =====
| |
| :Value: String
| |
| :Usage: <code>// @'''uso:hash''' 30d54f8ba24c0c6ec5710866e9b0839b2066a815 </code>
| |
| ::* userscripts.org will return the sha1(60)sum for the current user script.
| |
| :: '''NOTE:''' It is not necessary to define this key in a script as the meta.js routine will automatically return this key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| ===== @uso:rating =====
| |
| :Value: String or Number
| |
| :Usage: <code>// @'''uso:rating''' 4.00 </code>
| |
| ::* userscripts.org will return the rating of the current user script. Currently this is an unweighted average of all the peer reviews accurate to two decimal places.
| |
| :: '''NOTE:''' It is not necessary to define this key in a script as the meta.js routine will automatically return this key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| | |
| ===== @uso:fans =====
| |
| | |
| :Value: String or Number
| |
| :Usage:
| |
| ::: <code>// @'''uso:installs''' count </code>
| |
| ::: <code>// @'''uso:reviews''' count </code>
| |
| ::: <code>// @'''uso:discussions''' count </code>
| |
| ::: <code>// @'''uso:fans''' count </code>
| |
| ::* userscripts.org will return the current count for each respective type.
| |
| :: '''NOTE:''' It is not necessary to define these keys in a script as the meta.js routine will automatically return the key/value pairing via a http/https request to <nowiki>http://userscripts.org/scripts/source/</nowiki>''scriptid''.meta.js
| |
| | |
| ===== @attribution =====
| |
| | |
| :Value: String
| |
| :Usage: <code>// @'''attribution''' Attribution Name (Attribution Script Homepage)</code>
| |
| ::* There can be any number of @attribution keys in a script for multiple attribution support.
| |
| ::* Attribution may only be used if source [[#.40license|@license]] type is compatible.
| |
| ::* Example:
| |
| ::: <code>// @attribution Jane Doe (<nowiki>http://www.example.com/janedoe/scriptid</nowiki>)</code>
| |
| ::: <code>// @attribution Jack Doe (<nowiki>http://www.example.com/jackdoe/scriptid</nowiki>)</code>
| |
| ::: <code>// @attribution Jill Doe (<nowiki>http://www.example.com/jilldoe/scriptid</nowiki>)</code>
| |
| | |
| ===== @author =====
| |
| | |
| :Value: String
| |
| :Usage: <code>// @'''author''' John Doe</code>
| |
| ::* ''(Suggest not using this key in favor of [[#.40copyright |@copyright]])''
| |
| | |
| ===== @contributor =====
| |
| | |
| :Value: String
| |
| :Usage: <code>// @'''contributor''' Contributor Name (Contributor Homepage)</code>
| |
| ::* There can be any number of @contributor keys in a script for multiple contributor support.
| |
| ::* Example:
| |
| ::: <code>// @contributor Jane Doe (<nowiki>http://www.example.com/janedoe</nowiki>)</code>
| |
| ::: <code>// @contributor Jack Doe (<nowiki>http://www.example.com/jackdoe</nowiki>)</code>
| |
| ::: <code>// @contributor Jill Doe (<nowiki>http://www.example.com/jilldoe</nowiki>)</code>
| |
| | |
| ===== @homepage =====
| |
| | |
| :Value: URI
| |
| :Usage: <code>// @'''homepage''' <nowiki>http://www.example.com/myhomepage</nowiki></code>
| |
| ::* ''(Suggest not using this key in favor of [[#.40copyright |@copyright]])''
| |
|
| |
|
| == Examples == | | == Examples == |
|
| |
|
| <pre class='sample'> | | <pre class='sample'><nowiki> |
| // ==UserScript== | | // ==UserScript== |
| // @name My Script | | // @name My Script |
| // @namespace <nowiki>http://www.example.com/gmscripts</nowiki> | | // @namespace http://www.example.com/gmscripts |
| // @description Scripting is fun | | // @description Scripting is fun |
| // @include <nowiki>http://www.example.com/*</nowiki> | | // @include http://www.example.com/* |
| // @include <nowiki>http://www.example.org/*</nowiki> | | // @include http://www.example.org/* |
| // @exclude <nowiki>http://www.example.org/foo</nowiki> | | // @exclude http://www.example.org/foo |
| // @require foo.js | | // @require foo.js |
| // @resource resourceName1 resource1.png | | // @resource resourceName1 resource1.png |
| // @resource resourceName2 <nowiki>http://www.example.com/resource2.png</nowiki> | | // @resource resourceName2 http://www.example.com/resource2.png |
| // ==/UserScript== | | // ==/UserScript== |
| </pre> | | </nowiki></pre> |
| | |
| == Caveats ==
| |
| | |
| Changing the metadata of an installed script does not do anything, as this data is only accessed during installation. The script must be re-installed for these changes to take. Alternatively, [[config.xml]] can be modified manually.
| |
|
| |
|
| == See Also == | | == See Also == |
|
| |
|
| * [[API_reference|API reference]] | | * [[API reference]] |
| * [[Knowing Your Own Metadata]] | | * [[Knowing Your Own Metadata]] |
| * [[Third-Party Libraries]] | | * [[Third-Party Libraries]] |
Line 319: |
Line 141: |
| == Notes == | | == Notes == |
|
| |
|
| [[Category:API Reference|*{{FULLPAGENAME}}]] | | [[Category:API Reference]] |
Description
The metadata block is a section of a user script that describes the script.
It usually contains the script name, namespace, description, and include and exclude rules.
The metadata block appears in JavaScript line comments and may appear anywhere in the top level Greasemonkey code scope of the script, but is usually near the top of the file.
If the metadata block includes a key that Greasemonkey does not understand, it will simply be ignored.
Some authors choose to include their own keys, and userscripts.org defines a set of metadata keys for varying purposes.
It is important to note that all of the information specified in the metadata block is parsed and loaded at install time only.
Although script authors may edit the source of a user script on the fly, and see these changes reflected upon the next execution of the script, metadata is not reloaded upon every execution.
To change the metadata Greasemonkey uses, the script must be reinstalled.
Syntax
The metadata block must follow the format:
// ==UserScript==
// @key value
// ==/UserScript==
It must use line comments (//
) like above, not block comments (/* */
).
Some keys may have multiple values.
In all cases the key and value(s) are separated by whitespace.
@name
Example:
// @name Example Script
The name of the script.
This appears in the script manager and monkey menu, and is also the unique identifer of a script (within a #@namespace).
If no name is provided, it will be derived from the file name.
@namespace
Example:
// @namespace http://www.example.com/gmscripts
The combination of namespace and name is the unique identifier for a Greasemonkey script.
If a script is being installed, and a script what that same name and namespace already exists, it will be replaced by the new script.
Otherwise, the new script is added to the set of installed scripts.
A script author will usually put all of their scripts under one common namespace, and then assign each script a unique name.
While the namespace is non-semantic, a URL is often used.
Some authors use the common home page for the collection of scripts they have written.
But remember, the namespace can be any unique value.
@description
Example:
// @description This script even does the laundry!
Just a brief summary of what the script does, presented to the user as the script is installed, and in the manage dialog.
@include
Examples:
// @include http://www.example.com/*
// @include http://*
// @include *
See Include and exclude rules.
There can be any number of @include rules in a script.
@exclude
Examples: see @include above
See Include and exclude rules.
There can be any number of @exclude rules in a script.
@resource
- Compatibility: Greasemonkey 0.8.0+
Example:
// @resource resourceName http://www.example.com/example.png
There can be any number of @resource keys in a script.
While the resourceName is non-semantic, it should comply with JavaScript identifier restrictions.
Each @resource must have a unique name.
Each @resource is downloaded once, when the script is installed, and stored on the user's hard drive alongside the script.
The URL specified may be relative to the URL the script is being installed from.
These named resources may be accessed through GM_getResourceText and GM_getResourceURL respectively.
@require
Compatibility: Greasemonkey 0.8.0+
Example:
// @require http://www.example.com/example.js
There can be any number of @require keys in a script.
Each @require is downloaded once, when the script is installed, and stored on the user's hard drive alongside the script.
The URL specified may be relative to the URL the script is being installed from.
@unwrap
Compatibility: Greasemonkey 0.8.1+
Example:
// @unwrap
This declarative key has no associated value.
It changes the interpretation of the script as it executes.
Normally, greasemonkey scripts are wrapped in an anonymous function when they are executed.
This behavior started in very early versions of greasemonkey, which ran scripts directly in the content page, to separate their variables from those in the page.
In later versions, it remains because isolating the script from the sandbox scope still helps in certain cases.
This key is strongly recommended to only be used for debugging purposes.
Examples
// ==UserScript==
// @name My Script
// @namespace http://www.example.com/gmscripts
// @description Scripting is fun
// @include http://www.example.com/*
// @include http://www.example.org/*
// @exclude http://www.example.org/foo
// @require foo.js
// @resource resourceName1 resource1.png
// @resource resourceName2 http://www.example.com/resource2.png
// ==/UserScript==
See Also
Notes