[Greasemonkey] Getting currently signed on user without parsing html or dom

Jonas Galvez jonasgalvez at gmail.com
Sun May 28 07:15:04 EDT 2006


daddydave wrote:
> var usermatch = new Array();
> usermatch = ptext.nodeValue.match('Signed in as ([^ |]* |)');
> [...]
> (By the way, can I just say "var usermatch;" instead of  "var
> usermatch = new Array();" ? It seems to work either way)

You don't have to declare a variable before assigning a value to it.
Also, String.match() creates the array for you. There's no logic in
trying to create it before. Whatever value usermatch may have will be
replaced by match()'s return value. In your code, usermatch[] is
initially completely unused. It's there just to waste memory.

var usermatch = ptext.nodeValue.match...

That should suffice.

--Jonas Galvez


More information about the Greasemonkey mailing list