Am 03.07.2011 10:51, schrieb ericc:
Hi all

Since a long time I use a script found in the wiki (http://
wiki.greasespot.net/Knowing_Your_Own_Metadata) to auto-update my
scripts.
It always worked since Firefox 3

This morning, I install Firefox 5 and update to GreaseMonkey 0.9.6.
None of my scripts works anymore :-(
In the error console, I see :
"Error: /\/\/ @/ is not a function"

...

Problem seems to come from this line "var lines = metadataBlock.split(/
\n/).filter(/\/\/ @/);"

Someone can help me, to solve this ?

Thanks in advance

ericc


Hi Ericc,

Well, "Array.prototype.filter" expects a callback-function as parameter, that expects an item from the filtered array as parameter. The callback function implements the filter and returns "true" in case the array item should be in the result or "false" if not. The callback-function is called once with each item in the filtered array.

See also here for more information: http://www.tutorialspoint.com/javascript/array_filter.htm

From your code, I guess the filter is supposed to only return lines that contain "// @". The following implementations are imaginable:

isMetadata = function (item) {
    return (item.indexOf("// @") > -1);
}

var lines = metadataBlock.split(/\n/).filter(isMetadata);

This is believed to be rather fail safe if just called with correct userscripts. However the reasonableness of implementing such functions for these purposes is questionable in general. Depending on what you expect to filter out, you could also find easier code. If you are sure you just want to get rid of the first and the last line that open and close the metadata block, this would also do fine

var lines = metadataBlock.split(/\n/).slice(1, -1);

which I believe is not only less confusing but also faster.

Chris

P. S.: I wonder why it worked beforehand.

--
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to