AutoLink user script

AutoLink turns plain text URLs, email addresses, bug numbers, ISBNs, and US phone numbers into links. For example, it turns all of these into links:

  • http://www.squarefree.com/userscripts/
  • jruderman@gmail.com
  • Bug 162020
  • Bug 162020 comment 0
  • ISBN 0-340-82899-4
  • (555) 555-5555

You can add new filters if you know how to use JavaScript regular expressions. Here is an example filter, rewrapped to fit in my blog:

  {
    name: "Bug number",
    regexp: /bug \#?(\d+)/ig,
    href: function(match) {
      return
        "https://bugzilla.mozilla.org/show_bug.cgi?id=" + 
          match[1];
    }
  }

To install a user script into Firefox, install Greasemonkey, restart Firefox, open the user script, and select "Install User Script..." from the Tools menu.

23 Responses to “AutoLink user script”

  1. CypherBit Says:

    Excellent, I’ve been using your AutoLoginJ, Valid XHTML, Bookmarklets to User Scripts and have now added AutoLink. They’ve become indispennsible.
    Thank you.

  2. børge Says:

    Can I replace linkification with this? Or is it not as good when it comes to detecting links?

  3. Phil Ringnalda Says:

    Very nice: excellent job of keeping your modifications obvious.

    The ISBN regex needs a couple-three tweaks: they can be either \d-\d{3}-\d{5} or \d-\d{2}-\d{6}, and the last “digit” is a check digit that’s (mod 11) of a weighted sum of the rest, so it’s actually [\dXx], and I have the feeling that I’ve seen a fair number written with spaces instead of the correct dashes, but I’ll have to look around to see if that’s really true.

  4. davidbisset.com » Greasemonkey: AutoLink User Script Says:

    […]

    davidbisset.com

    Greasemonkey: AutoLink User Script Turns plain text URLs, email addresses, bug numbers, ISBNs, and US phone numbers into links. [ via […]

  5. Phil Ringnalda Says:

    Wups, I was still being anglocentric: we also want to match “Historia de la Psicología. ISBN: 94-309-2299-7.” Per the hyphenation instructions, the first hyphen can be after one to five digits, the second hyphen can be after three to eight digits, and only the third hyphen is fixed before the last digit/X. Um. ((\d(-)?){9}[\dXx]) maybe?

  6. Aankhen Says:

    That is some excellent JavaScript. I have a small quibble with it though — it seems to be putting a lot of functions and variables in the global namespace. Could it be wrapped with function() { … } or something of the sort?

  7. Jesse Ruderman Says:

    Aankhen, Greasemonkey 0.3.3 and higher does that automatically.

  8. Jesse Ruderman Says:

    Thanks Phil. I uploaded a new version that uses your regular expression.

  9. curious Says:

    This script does not appear to be gmail friendly… shrugs..

  10. Jesse Ruderman Says:

    Curious, can you elaborate on what’s wrong with the script at Gmail for you? It has some special-casing for Gmail (search autolink.user.js for “Gmail”), and it works for me at Gmail.

  11. curious Says:

    Bahh humbug… had an old version of Greasemonkey!

  12. —–+—+—– :: greasmonkey AutoLink :: May :: 2005 Says:

    […] ;

    May 23, 2005

    greasmonkey AutoLink
    Filed under: sweet, cool

    Jesse Ruderman » AutoLink user script This is so great. A long long time the thing I’ve […]

  13. Mike Wills Says:

    This should be added to the script. It is for the UPS, USPS, and FedEx tracking.

  14. Sencer Says:

    In Conjuction with a certain userscript my Firefox would leak memory until it grew to sizes of over 150MB. I am in the process of tracking it down to a certain user script, and I think it _may_ be Autolink. Therefore I wanted to ask if anybody else has made similar observations?

  15. David James Says:

    Great tool! Unfortunately, it often gets confused by ‘bold’ tags that often occur in the middle of search results in Google or Gmail. I’ve posted fixes on my blog to solve this issue.

    See http://www.cs.toronto.edu/~james/firefox/2005/05/bold-autolinking-using-greasemonkey.html

  16. jeff Says:

    Autolink will turn:

    http://www.squarefree.com/userscripts/

    into a link, but will it turn

    http://www.squarefree.com/userscripts/

    into a script, as well?

  17. This is Martey Dodoo Says:

    Greasemonkey User Script for Washington Post RSS Query Strings

    Greasemonkey is a Firefox extension that allows changing the behavior of websites through the addition of “user scripts.” User scripts are also supported in the latest version of Opera, and in Internet Explorer through Trixie and the not-y…

  18. djet Says:

    What about links like hxxp? How can they be transormed into valid?

  19. gaz Says:

    Top quality script, very usefull!

  20. Johan Sundström Says:

    Beautiful work on the detail finish, playing nicely even in harsh page environments!

    I’ve done a tiny but useful modification to the script, adding an optional scope regexp parameter. When a filter is equipped with one, the filter will only be applied for pages whose URL matches the provided regexp. It’s mainly useful for keeping local environments separate, such as linking ticked id:s on your corporate network to the company issue tracker, while still linking bugs on the rest of the web to mozilla.org.

    Diff: http://www.lysator.liu.se/~jhs/userscript/*/autolink.diff

  21. Dave Says:

    Should this work with Greasemonkey 0.5.1? It doesn’t seem to do anything when I installed it using that version.

  22. Martey Says:

    The examples at the top of the page do not seem to work in 0.5.1 (making an attempted demostration of the Autolink script go horribly awry), but the user script does seem to work on other pages.

  23. Jesse Ruderman Says:

    Martey, I had the same problem using Greasemonkey 0.5.1 with branch nightlies of Firefox. I upgraded to Greasemonkey 0.6.1 and now it works.