Tampermonkey script to un-Gmail Google Contacts

By | February 2, 2025

When you click on a contact’s email address in the Google Contacts web app, instead of opening a new draft in your default email app with the “To” field populated with that email address, which is what it should do, Google Contacts opens a Gmail compose window.

I hate this behavior. While I do have a Gmail account, it is not my default email account, and I hardly ever use it. I want email addresses in Google Contacts to do what they do on every other web page: open a new draft in my default email app.

So I wrote a Tampermonkey script to implement that behavior. You can find it here. And the code is also below, in case you prefer to just copy and paste it from here.

Share and enjoy!

// ==UserScript==
// @name         un-Gmail Google Contacts
// @copyright    Copyright 2025 Jonathan Kamens
// @license      GPL
// @namespace    http://tampermonkey.net/
// @version      2025-02-03
// @description  change gmail links in Google Contacts to mailto: links
// @author       Jonathan Kamens <jik@kamens.us>
// @match        https://contacts.google.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

// Instead of displaying email addresses as mailto: links as it rightfully
// should, the Google Contacts web app sends you to Gmail when you click on
// them. This script changes the email addresses back into mailto: links so
// that when you click on them they open in your configured email app.
//
// Uses a mutation observer because the Contacts app dynamically inserts content
// into the page after the browser thinks the page is finished loading.

(function() {
    'use strict';

    let callback = (mutationList, observer) => {
        let addresses = document.evaluate(
            "//span[starts-with(@href,'mailto:') or " +
            "starts-with(@data-href,'mailto:')]", document);
        let addressElement;
        while (addressElement = addresses.iterateNext()) {
            let href = addressElement.getAttribute("href") ||
                addressElement.getAttribute("data-href");
            let addressString = href.substring(7);
            let anchor = document.createElement("a")
            anchor.setAttribute("href", `mailto:${addressString}`);
            anchor.innerText = addressString;
            addressElement.replaceWith(anchor);
        }
    };
    let observer = new MutationObserver(callback);
    observer.observe(document, {subtree: true, childList: true});
})();
Share

Leave a Reply

Your email address will not be published. Required fields are marked *