18

I'm trying to figure out how can I add a button to the Gmail compose window.

In "Gmail Labs" they have some extensions that add certain buttons For example "Send & Archive" button and "Inserting images" button, so I assume this is possible.

I checked their API here and it seems that you can either add a gadget to left sidebar or use contextual gadgets that are dependent on the message context. I'm looking for a way to add a button to the toolbar of the compose window, and both options don't seem to support it.

Do you know how can this be done?

If it's not possible using Gmail API, is there another way I can achieve this? Maybe by creating a Google Chrome extension or user scripts?

I would appreciate any info that can direct me in the right direction.

Thanks.

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
Ran
  • 391
  • 1
  • 4
  • 10

2 Answers2

24

The Gmail Labs have special permissions because they are written by Google Employees, unfortunately we mortals don't have such power. There is a way around it of course and you've correctly pointed out that it is to make a Chrome Extension or a UserScript. If you choose to do a Chrome Extension it will just be a wrapper for a UserScript anyway

You will have to create and inject the button programmatically. This will involve quite a bit of scouring the Gmail source code (spoiler: it's ugly).

Without more details about what you want to do, I won't be able to provide much more help but I can help you with one problem right away. You have to make your script wait until the Gmail loading process is done which is a bit of a challenge. This is the solution I'm currently using in Minimalist:

function bootstrap() {
    target = document.querySelectorAll('.vt:not(.SFzvCe)');
    if (document.querySelectorAll('html.xiu1Fc, html.aao')[0] == null) {
        return;
    }
    if (target.length > 0) {
        // loaded, do stuff
    } else {
        window.setTimeout(bootstrap, 200);
    }
}
window.addEventListener('DOMSubtreeModified', bootstrap);

That version waits for the chat to fully load. Let me know if you have any other questions: @anstosa

mshell_lauren
  • 5,171
  • 4
  • 28
  • 36
Ansel Santosa
  • 8,224
  • 1
  • 28
  • 39
  • Any pointers for unofficial APIs or how to extract elements from GMail user interface? – Mikko Ohtamaa Aug 03 '12 at 09:08
  • 3
    The only one that I know of is James Yu's [Gmailr](http://www.jamesyu.org/2011/02/05/introducing-gmailr-an-unofficial-javscript-api-for-gmail/). I haven't used it personally but I've looked at the code and it's extremely well executed and fairly full-featured. – Ansel Santosa Aug 03 '12 at 15:02
  • 1
    At this point [gmail.js](https://github.com/KartikTalwar/gmail.js) looks like the better library, inspired by Gmailr. There's also a [chrome extension](https://github.com/KartikTalwar/gmail-chrome-extension-boilerplate) project to get you started. – Yarin Feb 03 '16 at 13:19
0

You can use InboxSDK for that. Here is documentation link

Also you have a Hello world repo, where is a solved your problem hello repo

Demir Agovic
  • 33
  • 1
  • 8