Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

google chrome - Gmail extension/gadget API - how to add a button to the compose toolbar?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...