Include and exclude rules: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Reset back links... sf)
No edit summary
Line 1: Line 1:
__NOTOC__
{{Greasemonkey Manual TOC}}
[[User script]]s specify include and exclude rules in the [[metadata block]].
[[User script]]s specify include and exclude rules in the [[metadata block]].


Line 20: Line 17:
== Greaseable schemes ==
== Greaseable schemes ==


[[#http: |General]] | [[#file: |file:]] | [[#about: |about:]]
Greasemonkey will run scripts only on documents loaded from particular [http://tools.ietf.org/html/rfc3986#section-3.1 schemes].
By default, those are:


=== http: ===
* http
=== https: ===
* https
=== ftp: ===
* ftp
=== data: ===
* data


[[#top |top]] | [[#Greaseable_schemes |back]]
Greasemonkey will also run scripts on:


=== file: ===
; file:
: Only if <code>greasemonkey.fileIsGreaseable</code> is set to <code>true</code> in [http://kb.mozillazine.org/About:config about:config].
: Only if <code>greasemonkey.fileIsGreaseable</code> is set to <code>true</code> in [http://kb.mozillazine.org/About:config about:config].
; about:
: Only if <code>greasemonkey.aboutIsGreaseable</code> is set to <code>true</code> in [http://kb.mozillazine.org/About:config about:config].<br>(But about:blank is always allowed.)


[[#top |top]] | [[#Greaseable_schemes |back]]
In both cases this restriction is intended to prevent security/privacy vulnerabilities.
 
=== about: ===
: Only if <code>greasemonkey.aboutIsGreaseable</code> is set to <code>true</code> in [http://kb.mozillazine.org/About:config about:config].  about:blank is always allowed.
 
[[#top |top]] | [[#Greaseable_schemes |back]]


== Magic TLD ==
== Magic TLD ==

Revision as of 17:56, 3 February 2010

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 within the allowed Greaseable schemes.

top

Greaseable schemes

Greasemonkey will run scripts only on documents loaded from particular schemes. By default, those are:

  • http
  • https
  • ftp
  • data

Greasemonkey will also run scripts on:

file
Only if greasemonkey.fileIsGreaseable is set to true in about:config.
about
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 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