Google Contacts Autocomplete

Last update on Aug 29, 2008

Creates a autocompleter next to email form boxes with your Google Contacts similar to the list of contacts when using the "to" field on Gmail. You have to be signed into Gmail for this to work. Handy for filling "send to a friend" forms.

Additional info:
------------------------------------
- Add a comma or semicolon to the end of the email address you entered to get another autocompleter to make a separated list of emails.

- Your Gmail address will always be the top suggestion so it is easy to fill in your address.

- Add your additional email addresses to the source. They will be shown at the top of all suggestions. Makes the script useful for filling in to and from on forms.

- Default settings sort contacts by "affinity" (probably Google's representation of contact frequency)

- Google Apps for Your Domain users check the source comments to enter your domain

Changelog:
------------------------------------
v8
- When the focus leaves the email field, the suggestions automatically hide immediately.

v7
- The default download location for contacts is now the XML file so that it sorts the results by "affinity" (probably contact frequency) and not alphabetically. An option still exists to use the CSV method. (Thanks gantt for the suggestion and Ionut Alex Chitu for explaining why the XML file is better). Also, the XML file contains your GMail address so that it will be the default result.

v6
- Add your email addresses to the souce. They will be shown at the top of all suggestions (Thanks Oskar for the suggestion)

v5
- Comment for Apps for Your Domain users (Thanks gantt)

v4
- Add a comma or semicolon to the end of the email address you entered to get another autocomplete to make a separated list of emails. (Thanks benjaminm)
- Put version in the description instead of the name of the script so that you can still tell the version but don't install multiple versions.

v3
- Updated which sites the script applies to
- Increased length of time before it auto-hides (and included a setting)
- Updated how it matches so that it only matches at the beginning of words
- Fixed bug where it was case sensitive
- Fixed/updated highlighting
- Added an option for the CSV URL (should help Apps users)

v2
- Possible bug fix that kept it from working for some users

v1
- First release




You could comment on this script if you were logged in.

16 comments Feed-icon

1 point
login to vote
mattkolb script's author
Posted Aug 28, 2008

I updated the script so that if you aren't focused on the input field anymore, it automatically hides the suggestions immediately instead of waiting a few seconds.

1 point
login to vote
janp scriptwright
Posted Jul 30, 2008

I also really like this script. Very handy in many situations.
Sometimes it appears in not mail fields. In this cases it's little annoying of having the suggestion list in front of the next input field. So I added margin-left: 25px; to the div.autosuggest class. Now I can keep on filling out my forms. Actually it would be better to let the box disappear when leaving the input field.

1 point
login to vote
gantt scriptwright
Posted Jul 20, 2008

Thanks for implementing some of my suggestions. It would be nice to somehow store the address book locally and refresh it every x hours/days, but the current implementation is pretty good.

1 point
login to vote
benjaminm user
Posted Jul 17, 2008

I messed around with this script on my computer, and made it so that (at least on firefox 2, linux) it will allow users to enter comma separated lists of emails. hope this helps!

In _b.AutoSuggest.prototype.doAjaxRequest, change the beginning of the function to look like this:

      _b.AutoSuggest.prototype.doAjaxRequest = function (input)
      {
      	// check that saved input is still the value of the field
      	if (input != this.fld.value)
      		return false;
      
              // only look at the text after the last comma
              var comma = -1;
              while ( input.indexOf(",", comma) >= 0 ) {
                      comma = input.indexOf(",", comma) + 1;
              }
              if ( comma >= 0 ) input = input.substring(comma);
              // trim
              input = input.replace(/^\s*([\S\s]*?)\s*$/, '$1');
      

and in the function _b.AutoSuggest.prototype.setHighlightedValue, change the first part of the function to look like this:

      _b.AutoSuggest.prototype.setHighlightedValue = function ()
      {
      	if (this.iHigh)
      	{
                      // get the text up until the last comma
                      var input = this.fld.value
                      var comma = -1;
                      while ( input.indexOf(",", comma) >= 0 ) {
                              comma = input.indexOf(",", comma) + 1;
                      }
                      if ( comma >= 0 ) input = input.substring(0,comma) + " ";
                      else input = "";
      
      		this.sInp = this.fld.value = input + this.aSug[ this.iHigh-1 ].value;
      

1 point
login to vote
Posted Jul 17, 2008

This would be a great addition to the Better Gmail 2 extension for Firefox (lifehacker.com)

1 point
login to vote
gantt scriptwright
Posted Jul 16, 2008

For Google Apps, the URL is: https://mail.google.com/a/EXAMPLE.COM/contacts/... .

Other suggestions would be to add support for multiple addresses separated by commas and to no longer change the title of the script (it's installed as a new script).

1 point
login to vote
mattkolb script's author
Posted Jul 16, 2008

1) I updated the pattern to be more accurate. Thanks for the suggestion.
2) I doubled the length of time before the suggestions are hidden. I didn't want to make it show indefinitely because some people might be running other greasemonkey scripts or the site might be doing their own autocomplete. I didn't want it to be permanently in the way. I also added a setting at the top of the script. Tip: Just hit your down arrow. It keeps the autocomplete from going away, and you can keep typing.
3) I sort of took your suggestion. I made it match the beginning of words and used spaces as a word separator. So "se" would match "Seth Green" or "Bob Sessums" but it wouldn't match "Johnny Appleseed"
4) I decided not to use the XML file. After checking, the XML file for my contacts was almost 7 times larger (11KB vs 75KB). Also the parsing for CSV is already in there.
5) Highlighting fixed
6) Highlighting fixed

For Apps for your Domain users, I also added a handy little setting at the top of the script that should be easy to change for the URL to get it to download from your Gmail account since the URLs are different for Apps for your Domain users. I would appreciate someone letting me know what the URL is though so I can make it even easier on people.

I also made the matching for names/emails case-insensitive. Not sure why I didn't see this problem before.

1 point
login to vote
gantt scriptwright
Posted Jul 16, 2008

Some suggestions:
1) improve the excluding pattern: http*://*.google.com/*, http*://google.com/*
2) increase the delay for hiding the suggestions. They disappear way too quickly. A better idea is to hide the list only when you click somewhere in the page.
3) Only match prefixes: if I type "ne", don't match janet because it doesn't start with "ne". Learn from Gmail's autocomplete feature.
4) Don't use the CSV file. Try this XML file: http://docs.google.com/c/data/contacts?max=1000
5) Stop highlighting names when you are only matching email addresses.
6) Start to match names. They are more important than email addresses.

1 point
login to vote
mattkolb script's author
Posted Jul 15, 2008

It is pulling contacts from your normal Gmail list. If you go to your Apps address, click Contacts on the left, click Export in the top right, choose to download all contacts, and post the URL of the file you downloaded, I will update it to work with Apps.

1 point
login to vote
Posted Jul 12, 2008

So is this pulling contacts from my Gmail list or my Google Apps Gmail list? If regular Gmail, how can I force it to use Apps, whilst remaining logged in to both?

1 point
login to vote
mattkolb script's author
Posted Jul 11, 2008

It isn't turned on for Google sites because most of the Google sites already have this feature. It would be redundant and most likely just get in the way.

Gina: Not sure why you were getting the error. I updated that line a little bit so that it might fix your problem. I removed my development copy and am using the copy hosted here without problems.

It shows up on any form element with the word "to" or the word "mail" in the name or the label of the input so it might not show up all places you expect. If there are any suggestions on a better way to decide when to display it, please let me know.

1 point
login to vote
Posted Jul 11, 2008

Hiii, I liked this script.. Can u tell me the license? Can i modify the script and host it?

1 point
login to vote
Posted Jul 10, 2008

[Addendum/Update: Okay, I see it working for me when I try Hotmail (ugh). No problems so far, and it's definitely different than the dropdown I was getting with Reader (though I still insist Reader didn't work for me that way before today :-), so that must be something else unrelated. In any case, so far, so good since my memory is mush when it comes to addresses.]

1 point
login to vote
Posted Jul 10, 2008

@Chuck this script is disabled on google.com; I think Reader typically pulls from your address book anyway

Just installed to try, hopefully it works.

1 point
login to vote
Posted Jul 10, 2008

Works for me, I'm happy to report ... I'm thinking maybe it was pulled, edited, and re-upped?, as my first two attempts to install brought me to the homepage, not the install script dialog ... on the third attempt, I got the usual install routine and a quick test (sending an e-mail to a Gmail contact from within Google Reader) was successful.

1 point
login to vote
Gina Trapani scriptwright
Posted Jul 9, 2008

Love the idea of this script, but can't get it to work. My error console says:

Error:
Source File: file:///[....]./gm_scripts/google_contacts_autocomp/google_contacts_autocomp.user.js
Line: 1823

This is the line:
window.addEventListener('load', go(), false);

You could comment on this script if you were logged in.