Menu

Script_injection_rules

mmartz

Getting StartedInstalling ScriptsManaging ScriptsMonkey MenuCreating ScriptsEnvironmentOther Useful ToolsAPI

In general user scripts should specify at least one @include or at least one @exclude in the UserScript metadata block.

The script will execute if a user script matches any @include, as long as it does not match an @exclude or a global exclude.

If no @include is provided, @include * is assumed. That is, every URL will be matched within the allowed Pattern recognitions.

Patterns

Patterns apply to @include, @match, and @exclude values including global excludes unless otherwise specified.

Pattern recognition

Pattern matching

Regular Expressions

Globs

// ==UserScript==
//
// @include   http://www.example.org/*
// @include   https://www.example.org/*
// …
// @match     http://www.example.net/*
// @match     https://www.example.net/*
// …
// @exclude   http://www.example.com/*
// @exclude   https://www.example.com/*
//
// ==/UserScript==

Regular Expressions

// ==UserScript==
//
// @include   /^https?:\/\/www\.example.(?:org|net)\/.*/
// …
// @exclude   /^https?:\/\/www\.example.com\/.*/
//
// ==/UserScript==
  • Currently these patterns are supported on @include, and @exclude and global excludes only.
  • This pattern is always treated as case insensitive therefore a Url in the address bar of HTTPS://WWW.EXAMPLE.ORG/ is the same as https://www.example.org/. However please don't shout.

  • @exclude values may look the same but prevent the script from being executed on this pattern regardless of @include or @match allowances.

  • JavaScript RegExp currently allows forward slashes and trailing matches to be non-escaped and omitted respectively. See special characters. Therefore /^https?://www\.example.org// should be the same as /^https?:\/\/www\.example.org\/.*/ in this context. However in other contexts the shorthand syntax may be considered non-portable and may not be recommended due to potential cross-browser differences. Better to be safe than sorry later on?

Pattern recognition

| file: | about: | unmht:| .tld

http:

https:

ftp:

  • Generally these are the most common schemes, or protocols, that user scripts inject into.

file:

about:

unmht:

.tld

Getting StartedInstalling ScriptsManaging ScriptsMonkey MenuCreating ScriptsEnvironmentOther Useful ToolsAPI

Notes


Related

Wiki: Greasemonkey_Manual:API
Wiki: Greasemonkey_Manual:Creating_Scripts
Wiki: Greasemonkey_Manual:Environment
Wiki: Greasemonkey_Manual:Getting_Started
Wiki: Greasemonkey_Manual:Installing_Scripts
Wiki: Greasemonkey_Manual:Managing_Scripts
Wiki: Greasemonkey_Manual:Monkey_Menu
Wiki: Greasemonkey_Manual:Other_Useful_Tools
Wiki: Metadata_Block
Wiki: User_script
Wiki: config.xml