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

↘锁芯ラ 提交于 2019-11-28 18:22:46
Ansel Santosa

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!