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

后端 未结 1 1616
南旧
南旧 2020-12-13 15:16

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 \"Sen

相关标签:
1条回答
  • 2020-12-13 15:30

    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

    0 讨论(0)
提交回复
热议问题