AutoLink filters

If you've made new AutoLink filters, please post them in comments wrapped in <pre> or post them in your blog and use trackback. Feel free to request filters, too.

For tutorials and references on using regular expressions in JavaScript, see http://del.icio.us/jesser/regexp+javascript.

Tips for testing filters:

  • Use the Edit button in Greasemonkey 0.3.3+. As soon as you save your changes in your text editor, they will apply the next time you load or reload a page.
  • Create a test page similar to autolink-test.html. Then you can test each change by saving autolink.user.js in your text editor and reloading the test page.
  • Use Thomas Russell's regular expression tool or the JavaScript Environment to test your regular expressions.

12 Responses to “AutoLink filters”

  1. curious Says:

    I didn’t want to match on every 5 digit number for zip, so this will match any 5-4 zip and “statecode zip” would love to see an autolink for full addresses ;)

      {
        name: "Zip --> Google maps",
        regexp: /([A-Z]{2} (\d{5}))/g,
        href: function(match) { return "http://maps.google.com/maps?q=" + digits(match[0]) ; }
      },
      {
        name: "Zip --> Google maps2",
        regexp: /(\d{5}-\d{4})/ig,
        href: function(match) { return "http://maps.google.com/maps?q=" + match[0] ; }
      },
    
  2. curious Says:

    I just noticed that my test case for the 5-4 could probably use at a minimum a space before the digits since it fasly triggers on one of your “these are not phone numbers” test…

    Perhaps we need an autolink acid test ;)

  3. Jesse Ruderman Says:

    I’m thinking of making AutoLink ignore any matches that are prededed or followed by a number or letter. Individual filters might be able to override this with some kind of flag.

  4. Kjell S. Says:

    I wanted a filter that handled hxxp links, so hacked together this by looking at the already exisiting filters. I have no idea if it is optimal, but it works.

    {
        name: "Munged text link",
        regexp: /hxxps?\:\/\/([^"\s\]*[^.,;'">\:\s\)\]\!])/g,
        href: function(match) { return "http://" + match[1]; }
      },
    
  5. Edward Lee Says:

    Quick fixes for the ISBN test cases to not link at all.

    ISBN –> Amazon

    /ISBN( number)?:? \#?((\d(-)?){9}[\dx])(?!\d)/ig

    Fixes: ISBN 12345678901

    US phone number –> Skype

    /((\(\d{3}\)[\s-]?)|(\d{3}(\s|-)))\d{3}[\s-]\d{4}(?!\d)/g

    Fixes: ISBN 123456789-123-12345-1

    Basically it does a look ahead to make sure the following isn’t a number.

  6. Edward Lee Says:

    Oh. Perhaps the lookahead for the ISBN should also include – instead of just \d

    Failure: Second Edition: 2003 ISBN: 0-13-0444911-3
    Success: Second Edition: 2003 ISBN: 0-13-044911-3

    /ISBN( number)?:? \#?((\d(-)?){9}[\dx])(?![\d\-])/ig
  7. Hipster Dufus Says:

    UK Post Codes

      {
        name: "Post Code",
        regexp: /[A-Z]{1,2}\d{1,2}[A-Z]{0,1}\s\d[A-Z]{2}/g,
        href: function(match) { return "http://maps.google.co.uk/maps?q=" + match[0]; }
      },
    
  8. Joey Says:

    Reporting a bug:

    Cause’s gmail to mess up reply’s and forwarding.

    Steps to reproduce:
    1: open an email with URLs
    2: Hit reply or forward at the bottom

    expected: operate normally
    what happens: it removes URLs from the email to-be- replied or forwarded and messes things up.

    Just thought you might wana know.

  9. Jesse Ruderman Says:

    WFM with a plaintext email containing a bug number.

  10. curious Says:

    There are some sites that do not “linkify” the urls because they want to avoid links being traced back to them…

      {
        name: "Plain text link",
        regexp: /https?\:\/\/[^"\s\]*[^.,;'">\:\s\)\]\!]/g,
        href: function(match) { return "javascript:z=document.open();z.write("");z.close();"; }
    
      },
    

    Do a similar thing to the munged text (since it is more then likely that the person munged the text to avoid such trace backness)… If there is a better way to hide referers or whatever… please let me know.

  11. curious Says:

    Bug: textarea truncates…
    This happens on autolink, but not on autologin

    
    
    
    
    {put 500 lines of text here}
    
    
    
    
    
  12. curious Says:

    erms… ok.. pre doesn’t escape out html…

    basicly put 500 lines of text in a textarea, with autolink on it’ll truncate to around 250ish lines