简体   繁体   English

如何使用Javascript以编程方式打开GMail中的“撰写”框

[英]How can I programatically open the “compose” Box in GMail using Javascript

I am creating a script for Gmail, which open Single compose Box in the Gmail page like when click on compose button. 我正在为Gmail创建脚本,该脚本会在Gmail页面中打开“单个撰写框”,就像单击“撰写”按钮时一样。 I have tried the following code but sometimes it opens multiple compose Boxes. 我尝试了以下代码,但有时会打开多个撰写框。 But I want to open only one compose box when script will run. 但是我只想在脚本运行时打开一个撰写框。 Is there any other way to open Compose Box. 还有其他方法可以打开“组合框”。

        var down = new MouseEvent('mousedown');
        var up = new MouseEvent('mouseup');
        var elem = document.getElementsByClassName("T-I-KE")[0];
        elem.dispatchEvent(down);
        elem.dispatchEvent(up);

Compose Box 组成框

You could be more robust and only dispatch the mouse events if the compose frame is not showing. 您可能会更健壮,并且仅在未显示撰写框时才调度鼠标事件。 The following seems to work for me. 以下内容似乎对我有用。

var composeButton = document.getElementsByClassName("T-I-KE")[0];    
var down = new MouseEvent('mousedown');
var up = new MouseEvent('mouseup');

function openCompose() {
    if (document.querySelectorAll('.dw.np').length) {
        composeButton.dispatchEvent(down);
        composeButton.dispatchEvent(up);
    }
}

openCompose();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM