Difference between revisions of "Include and exclude rules"

From GreaseSpot Wiki
Jump to navigationJump to search
m (sf... Dropping in partial core for 0.8.2's greasable schemes under new heading... will add overrides in a day or two after full testing... sf)
m (CR... sf)
Line 15: Line 15:


If no include rule is provided, <code>@include *</code> is assumed. That is, every URL will be matched.
If no include rule is provided, <code>@include *</code> is assumed. That is, every URL will be matched.
[[#top |top]]
[[#top |top]]



Revision as of 00:37, 28 September 2009

Book.png
Greasemonkey Manual
Using Greasemonkey
Installing Scripts
Monkey Menu
Getting Help
User Script Authoring
Editing
Environment
API

User scripts specify include and exclude rules in the metadata block.

The script will execute if it matches any include rule, as long as it does not match an exclude rule.

The rules are URLs, which can have a "wildcard" asterisk (*), which matches any string including the empty string. For example: http://www.example.com/foo/* will match http://www.example.com/foo/bar and http://www.example.com/foo/, but not http://www.example.com/baz/. A rule can have several wildcards or none, in which case the rule must match the entire URL exactly. Exclude rules look the same, and prevent the script from being executed. An example:

// ==UserScript==
// @include     http://www.example.com/foo/*
// @include     http://www.example.org/*.bar
// @exclude     http://www.example.com/foo/baz
// ==/UserScript==

If no include rule is provided, @include * is assumed. That is, every URL will be matched.

top

Schemes

http:

https:

ftp:

data:

file:

top

about:

top

Magic TLD

The only special syntax besides the wildcard is .tld. An include such as http://www.example.tld/* will match any top level domain, such as www.example.com, www.example.org, www.example.co.uk, and so on. One must be careful with this, to not accidentally leak data to a site that they did not mean to match. This list of TLDs includes a myriad of dual-segment TLDs (such as ca.us, aeroport.fr and kyoto.jp), beside the plain country or category codes (com, jp, se). For a full list see the Magic TLD page.

top