Include and exclude rules

From GreaseSpot Wiki
Revision as of 02:18, 19 February 2011 by (talk) (2ceRre Hi! I'm just wondering if i can get in touch with you, since you have amazing content, and i'm thinking of running a couple co- projects! email me pls)
Jump to navigationJump to search

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:* will match:

  • and,

but not:


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*
// @include*.bar
// @exclude
// ==/UserScript==

If no include rule is provided, @include * is assumed. That is, every URL will be matched within the allowed Greaseable schemes.

2ceRre Hi! I'm just wondering if i can get in touch with you, since you have amazing content, and i'm thinking of running a couple co- projects! email me pls

Extra schemes

Greasemonkey will also run scripts on:

Only if greasemonkey.fileIsGreaseable is set to true in about:config.
Only if greasemonkey.aboutIsGreaseable is set to true in about:config.
(But about:blank is always allowed.)

In both cases this restriction is intended to prevent security/privacy vulnerabilities.

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,,, 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, and, beside the plain country or category codes (com, jp, se). For a full list see the Magic TLD page.

Data scheme user scripts

Browsers can open windows in which all of the page top content is contained in a data scheme URI. For example, the below URI will display a HTML page that indirectly includes an image from as its sole content:

data:text/html;charset=utf-8,<html><head><title>data: test</title></head><body><img src=''></body></html></pre>

This link points to the above data URI and can be clicked to see it in action.

Firefox ignores unknown semicolon separated parameters in the header of a data URI (and the standards seem to leave this possibility open) which means if one adds say the string MyScript; in the header of the above URI, giving:

data:text/html;MyScript;charset=utf-8,<html><head><title>data: test</title>....

one can then use Include and exclude rules such as

@include data:text/html;MyScript;*

to trigger user scripts to run on a subtype of data URIs.

This ability can be useful if a user script creates one or more data URIs and then opens them. Augmenting the URIs with some extra marking can cause specific user scripts to run in their windows. For example, a user script can create a data URI that contains a HTML table and trigger a user script for it that allows the user sort it.