2005-08-29

Adopting and adapting AutoLink

It appears I've fallen back on reading Jesse Ruderman this summer, and on catching up again, I stumbled upon AutoLink, a userscript which linkifies things that looks like links, or that ought to become links (ISBN numbers, mail addresses, bugzilla ticket numbers et cetera). I haven't thought about that kind of script since my (web)server side programming days, some time on the other side of Y2k, but by now you can have as much, and indeed even more fun in client land as you only could server side back in those days. (Javascript was not by far as much fun then, either, but XMLHttpRequest, the DOM and emerging web standards have mended much of that since. :-)

Anyway, I was a bit surprised to find I'd be the first who would want to do contextual autolinking - linking bug id:s referred from web pages at work to the company Trac installation, bug id:s at Lysator pages to bugzilla.lysator.liu.se, and so on, but the adding that capability was a sheer joyful five minute task.

In short, AutoLink processes pages you visit for a list of regexp filters, trying each in turn for matches, and stylishly converts the matched text portion to a link. Each such filter is denoted by a name, a regexp, and a function returning a link, more or less creatively based on the matched text portion. I added an optional additional regexp scope parameter, limiting the match to only be considered for URLs matching the regexp, when given.

And that was it. I'll host my version here, but expect you might want to stick to Jesse's for future updates (there has got to be more people than me who feed things back up the pipe). Well, time I sent back my diff.

Something that has been puzzling me a bit since I started really getting to grips with GreaseMonkey, is that at least my 0.5.1 Final installation doesn't seem to want to play nice with the horde of user scripts out there who install themselves on the "load" event listener, with, typically, a window.addEventListener("load", init, false); call. Was there some unannounced API change to GreaseMonkey only trig scripts after the load event was already fired, rendering all such scripts ineffective? If so, I suppose it is a change for the better, script writing usability wise, but it might be a good idea firing off a faked load event to user scripts made for earler versions, if that is fasible.

My diff doesn't feature the change, but if my linked userscript won't work with your installation it just might be because I dropped the event listening portion from it.
Categories:
blog comments powered by Disqus