Have you tested you XPath in XPather? Have you tested the individual
steps in the JavascriptShell or FireBug? See:
function Main (){ ....}
Main();
this code looks wrong:
elm.parentNode.replaceChild(elmSpan, text);
It should be
elm.parentNode.replaceChild(elmSpan, elm);
In general it would help if you mentioned what errors you get.
Also with regard to wrapping. It can be easier to develop unwrapped,
and then wrap after everything works.
The OP did this properly, with an anonymous function, called directly.
Your way works, but it's not necessary to actually name the function.
You are correct that it's not necessary, though.
There are already a lot of example "linkify" scripts to look at for
examples across the web. Even more, there's a customizable one that
will easily let you specify custom replacements:
http://www.squarefree.com/2005/05/22/autolink/
Now, you're not looking to make <a> tags, so you can't use any of them
directly, but they'll all be very very close. One of the simplest
examples is probably:
http://ftp.iasi.roedu.net/mirrors/mozdev.org/greasemonkey/linkify.user.js#
As to your actual script:
> elm.parentNode.replaceChild(elmSpan, text);
This line fails horribly.
(And the error console reports it improperly. A case that my fix to
this doesn't catch, grr!)
The node "text" is a string. Even if it was the text node, it's not a
child of "elm.parentNode" so you can't operate on it directly.
The XPath here has already returned the text node that contained the
":)" so you don't want to try to drill down further from there.
> urlRegex.lastIndex = 0;
This (urlRegex) doesn't exist anywhere. smileyRegex perhaps?
> } catch (e) {
> GM_Log(e);
> }
There is no GM_Log (there is GM_log, though).
Finally, I'd move the element replace line to the bottom of the loop,
/after/ elmSpan is filled up completely. It's terribly minor, but may
help reduce just a little jitter.