Hi Chris Thank for the fast answer !
I found an equivalent solution thanks to http://www.hunlock.com/blogs/Mastering_Javascript_Arrays#filter I modify my code like this : function parseHeaders(metadataBlock) { var headers = {}; var line, name, prefix, header, key, value; var headGM = function(x) { // return true if x is from the GM headers var RegExp = /\/\/ @/; return String(x).match(RegExp); } var lines = metadataBlock.split(/\n/).filter(headGM); for each (line in lines) { [, name, value] = line.match(/\/\/ @(\S+)\s*(.*)/); And now it's work ! And yes it worked nicely until FF4 and even on Chrome with TamperMonkey, on various OS (Linux, WinXP) I know it's strange as when I made some search on the web, the function was not correct I guess that Mozilla have changed the version of Javascript for FF5 ! ericc On Jul 3, 11:22 am, "LWChris@LyricWiki" <[email protected]> wrote: > 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.
