[Greasemonkey] Control over metadata include/exclude regular expressions

Bill Donnelly donnelly at snowcrest.net
Wed Dec 7 06:20:09 EST 2005


I was messing with one of my exclude metadata regex's,
and wanted to use an "*" to modify something,
which is not allowed because asterisks are changed
into ".*" for us, and I also wanted to do some internal
regex stuff, too, which is "turned off" via backslash-quoting,
all done in the Gm-supplied convert2RegExp() function.

So I suggest a "feature" that allows complex
regular expressions for those who want to mess with
them to do so, while keeping current "simple" support.

What I came up with is that, if the include/exclude
metadata regex starts with a "^" (start of line),
then do not help the regex with the algorithm in
convert2RegExp() and pass it through unscathed.
(the function currently auto- prepends an "^" and appends a "$", too)

Except go ahead and support the .TLD support. (why not?)

(altho, I am leaning toward the "code" for the TLD
being more evident in the sense of "special" in case
that value is found in some URL somewhere, which
could occur, but probably won't -- maybe ---
I suggest something like ".TLD" capitalized (required),
or maybe "\.tld\" -- ?? -- probably not a huge deal)

Here's a simple example of a complex regex:

// @exclude       ^http.*://.*dailygrail.com.+$

I know we've has some major discussions over include/exclude
metadata regex stuff, but doing something like "*dailygrail.com*"
CAN be 'dangerous' if "dailygrail.com" is inside a complex URL.
There are other examples, too, real and imaginable, why super-simple
regex's can be problematic. (I hope I'm not opening up that
whole discussion again)


Anyway, attached find my mods in the convert2RegExp.js file.

I massaged the code for readability, and such, but I
really just added the feature as described above.
('sorry', I couldn't help myself ;o) )


In case it's not adopted, people can use this file
and the features it gives, personally, you just can't
publish your scripts with these complex regex's in
the include/exclude metadata, because they won't work
for the masses. It won't affect you, tho, except to
allow the new functionality for your scripts.


btw -- if you wanted to get 'fancy', you could change the
for loop conversion algorithm to a very fast (faster)
regex. (or a few) I didn't mess with that, tho.

For "fun" ('quickly'), something like: (NOT TESTED)

pattern.replace (/([.\$+{\[|()\]\\^?])/g), "\\$1");
pattern.replace (/\*/g), ".*");
pattern.replace (/\s/g), "");


p.s. on a separate note, I wanted to make one of my
script functions available to the browser global,
for bookmarklet usage, so I just did this,
which I think is correct: (it works)

unsafeWindow.checkColors = function (pbUndoIt) { checkColors (pbUndoIt) };

-------------- next part --------------
A non-text attachment was scrubbed...
Name: convert2RegExp.js
Type: application/x-javascript
Size: 11588 bytes
Desc: not available
Url : http://mozdev.org/pipermail/greasemonkey/attachments/20051207/66be7412/convert2RegExp-0001.js


More information about the Greasemonkey mailing list