Metadata Block: Difference between revisions
m →Other Keys: Added specific earliest period of time for getTime() in human readable format. |
m Added unwrap for debug purposes... I've never used this before and probably won't, so I don't know what type to set for "value" to be passed... very vague in trunk/src.. guess is null but not sure |
||
Line 33: | Line 33: | ||
:{| cellpadding="5" style="border-style:solid; background:#FFFFE0;" | :{| cellpadding="5" style="border-style:solid; background:#FFFFE0;" | ||
|+ Keys | |+ Keys | ||
! colspan=" | ! 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;">[[#.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;">[[#.40namespace |@namespace]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40exclude |@exclude]]</span></code> || <code><span style="background:#FFFFE0;">[[#.40require |@require]]</span></code> | ||
Line 106: | Line 106: | ||
::* 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. | ::* 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]). | :::* 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]). | ||
[[#top|top]] | [[#Syntax|back]] | |||
==== @unwrap ==== | |||
:Value: ? | |||
:Compatibility: [[Version_history#0.8.20090123.1|Greasemonkey 0.8.1+]] | |||
:Usage: <code>// @'''unwrap'''</code> | |||
::* Removes the anonymous function wrapper around scripts. For debug purposes. | |||
[[#top|top]] | [[#Syntax|back]] | [[#top|top]] | [[#Syntax|back]] |
Revision as of 19:02, 18 February 2009
Greasemonkey Manual |
Using Greasemonkey |
---|
Installing Scripts |
Monkey Menu |
Getting Help |
User Script Authoring |
Editing |
Environment |
API |
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 appears in JavaScript comments. It begins with the line
// ==UserScript==
and ends with
// ==/UserScript==
Everything between those lines is in the format
// @key value
If the metadata block includes a key that Greasemonkey does not understand, it will simply be ignored.
Other Keys | Examples | Caveats | See Also | Notes
Syntax
// ==UserScript==
// == @key value
// ==/UserScript==
- Value: Object
- Compatibility: Greasemonkey 0.2.5+
Keys Properties @name
@include
@resource
@unwrap
@namespace
@exclude
@require
@description
- All properties are optional
Properties
@name
- Value: String
- Usage:
// @name My Script
- The name of the script. This appears in the script manager and 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 Greasemonkey 0.8.20080609.0, new scripts will be stored under their own folder name in the gm_scripts folder and also include spaces to underscores conversion and other special characters. The scripts directory is also backed up into a folder called gm_scripts_08bak when migrating to version 0.8.20080609.0.
@namespace
- Value: URI
- Usage:
// @namespace http://www.example.com/gmscripts/
- 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.
- While the namespace is non-semantic, it should be your prefered internet homepage URI according to the 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://userscripts.org and let Greasemonkey supply one automatically. If you are creating one locally, authors may choose the URI specification standard of
http://localhost
for the URI value as being an anonymous local script, but runs the risk of another script with the same name and namespace overwriting it. - The NoScript add-on currently utilizes namespace filtering, and will properly sanitize user scripts that are not listed in the XSS white-list section of the options dialog.
@description
- Value: String
- Usage:
// @description This script even does the laundry!
- Just a brief summary of what the script does, to present to the user who is installing it.
@include
- Value: String
- Usage:
// @include http://www.example.com/*
- Refer to Include and exclude rules. There can be any number of @include rules in a script.
- You cannot edit a live script's @include and have it take effect.
@exclude
- Value: String
- Usage:
// @exclude http://www.example.com/foo/*
- Refer to Include and exclude rules. There can be any number of @exclude rules in a script.
@resource
- Value: String
- Compatibility: Greasemonkey 0.8.0+
- Usage:
// @resource resourceName http://www.example.com/resource.png
- 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 include local and remote resources into the current script at first install but not successive installs. A user is required to uninstall the current user script before installing a newer version if new resource keys or require keys are present.
- 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.
@require
- Value: String
- Compatibility: Greasemonkey 0.8.0+
- Usage:
// @require foo.js
- This metadata block key property may be used to include local or remote scripts into the current script at first install, but not successive installs.
- Once a script is installed, changing the @require or @resource values will have no effect. The script must be uninstalled and reinstalled.
- Similarly, if a user is updating their script and it contains new values, they must uninstall the current user script before installing a newer version .
- 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 Google AJAX Libraries API or YUI).
@unwrap
- Value: ?
- Compatibility: Greasemonkey 0.8.1+
- Usage:
// @unwrap
- Removes the anonymous function wrapper around scripts. For debug purposes.
Other Keys
Some user scripts contain other special keys in the metadata block. Some common keys found are @author
, @license
, @version
, @homepage
, @copyright
, @statussize
, or @defaulticon
.
These unsupported metadata keys serve no technical purpose and are ignored by the Greasemonkey extension, but can be read by human beings or utilized by other code.
- The Greasemonkey repository at userscripts.org currently parses some of these values to log and categorize thousands of scripts.
- The key
@version
proves to be vital in scripts that are self-updating. Usually, they will include a timestamp indicating the number of milliseconds that have expired since 1 January 1970 00:00:00 UCT, which can be generated by callingnew Date().getTime()
.
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==
// ==UserScript==
// @name Hello jQuery
// @namespace http://wiki.greasepot.net/examples
// @description jQuery test script
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});
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.