Include and exclude rules

From GreaseSpot Wiki
Revision as of 12:53, 14 December 2006 by LouCypher (talk | contribs) (add code tags, unlinkify example URLs)
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. 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.

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.

The following is a pseudo-code representation of the code that performs the regular expression searching in Greasemonkey that supports the TLD special function. The actual Javascript code is located in the extension convert2RegExp.js file.


  .     = actual required period character
  *     = any character
  !     = any character not a period
  []    = optional
  ()    = parenthetical grouping
  AND   = logical And
  OR    = logical Or
  ,     = logical Or

  Note that some "AND's" are implied, and Space characters are ignored.


*  AND
  OR  ( [ co.  OR  ci. ] !.  AND
     (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ) )
     !. [pvt.] ( k12., cc., tec., lib., state., gen. ) .  AND
     (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, )
     !. (,, ac,,,,,,,,,,,,,,,,,,,,,,,,,,, ac.yu,,, ad,, ae, aero,, af, ag,,,, ai,,, ak,, al, al,,,, am, an, ao,, aq, ar, ar, arpa,,,,,, as,,,,,,, at,,, au,,,,,, aw, ax, az, az, ba,, bb,,,
        bd, be,,, bf, bg, bh, bi,, biz,,,,,,, bj,, bm, bn, bo,,, br,, bs, bt, bv, bw, by, bz, ca, ca,,,
        cc,, cd, cf, cg, ch,,,,, ci,,, ck, cl, cm, cn,,
        co, co,,,,,,,,,,,,,,,,,,,,,,,,, co.yu,,, com,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, coop,, cr,, cs,, ct, cu,, cv, cx, cy, cz, dc, de, de,,,,, dj,
        dk,,, dm,,, do, dz,, ec,,, edu,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, edu.yu,,, ee, eg, eh,,, er,,,, es,, et,, eu,,,,,,,,,, fi,,,,,,,, fj, fk, fl, fm, fo,, fr,,,,,,, ga, ga,, gb,,, gd,, ge,,,,,, gf, gg, gh, gi,, gl, gm,, gn,,,,,,,,,,,,,,,,, gov,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, gp, gq, gr,,, gs,,, gt, gu, gu,,,,, gw,, gy,,,,, hi,,, hk,,, hm, hn,,,, hr, ht, hu,,,, ia,, id, id,,,,,,, ie, il,
        il, im, in, in,,,,,,, info,,,,,,,,,,, int,,,,,, io,
        iq, ir, is,, it,,,, je,,, jm, jo, jobs,, jp,,,,,,,,,, ke, kg,
        kh, ki,, km, kn,,,, kp, kr,
        ks,, kw, ky, ky,,, kz, la, la,,, lb, lc,, li, lk,,, lr, ls, lt,,,, lu, lv, ly, ma, ma,,,,, mc, md, md, me,,,,,,,,, mg, mh, mi,,, mil,,,,,,,,,,,,,,,,,,,,,,,,,,,
        mk, ml, mm, mn, mn, mo, mo,,,,,,, mp, mq, mr, ms, ms, mt, mt, mu,, museum,, mv,
        mw, mx, my, mz, na,,,, name,,,,,,, nc, nc, nd, ne, ne,,, net,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, nf,, ng,,, nh,, ni,,,,,,, nj, nl,, nm,, no,,,,,,,,,,,, np, nr,,, nu,, nvus,, ny, nz, oh,, ok,,,
        om,, or,,,,,,,, org,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, org.yu,,,,,, pa, pa,,
        pe,,,,, pf, pg, ph,, pk, pl,,,, pm, pn,,,,,, pr, pr,,,,,,, pro,,,,, ps,, pt,,, pw, py, qa,,,, re,,,,,,,,,, ri,,,, ro, ru,, rw, sa,,,,,,, sb, sc, sc,,,,,,,,,,,,, sd, sd, se,,,,,,,, sg, sh,,,,,,, si, sj, sk,,, sl,, sm, sn,, so,,,, sr, st,,, su,, sv,, sy, sz,,,,, tc, td,,,,,, tf, tg, th, tj,,
        tk, tl,, tm,,,,,,, tn, to,,,,,,,,, tp, tr, travel,, tt,, tv,
        tw,, tx, tz, ua,, ug, uk,,,, um,, us,,, ut,,,, uy,, uz, va, va, vc, ve,, vg, vi, vi,, vn,
        vt, vu, wa,,,,,,, wf, wi,
        ws, wv, wy,, xxx,,,,,
        ye,,,, yt, yu, za,,, zm, zw )