How to send Gmail messages using method-built Gmails

I want to create a Google Chrome extension that, among other things, will change the chat text based on the input. I will add a button next to the video, call and add the buttons of people under the name, and when I click, it will activate the changes. I don’t want to put more scripts on the page than I need, so I would like to be able to send messages the way Gmail will click “return” in the chat window. In addition, I want to show that both people in the chat use my extension by displaying the text in the chat window, just like the text “This chat is disconnected from recording”, and maybe if both use it, add extra material to chat. What I tried to do was create a simulated text area, and when the user "sends" it, take it and change it, and then paste it into the real one and send the new text.I can change the text, but I can not send it ...

Here is what I have so far, I put everything in setInterval to check if the chat window exists and add the appropriate material to it:

var chatBtnClone = setInterval(function() {
    if ($("body").find(".nH .NG").length > 0) {  //if chat is active

        var clone = $("body").find(".nH .NG .NJ").first();
        if (clone.children()[0].className.indexOf("chat") < 0) { //if already added my class
            var clonned = clone.clone();
            var clonnedChd = clonned.children().first();
            clonnedChd.attr("title", "Start encrypted chat");
            clonnedChd.on('click', function() {
                console.log("clicked chatBtn!"); //make sure it works
                var self = $(this);
                if (self[0].className.indexOf("chatEncX") >= 0) { //toggle button pic 
                    self.removeClass('chatEncX').addClass('chatEnc');
                    self.attr("title", "Stop encrypted chat");
                } else {
                    self.removeClass('chatEnc').addClass('chatEncX');
                    self.attr("title", "Start encrypted chat");
                }
            });
            clone.parent().prepend(clonned);
            clonned.find('.NK').removeClass("NK-Y8").addClass("chatEncX");
        }

        var chatBoxs = $('body').find(".nn .AD");
        var chatArea = chatBoxs.first().find(".nH textarea"); //get chat textareas
        if (chatArea.length === 1) {
            var clonChatArea = chatArea.first().clone();
            clonChatArea.removeAttr("id");
            chatArea.first().parent().append(clonChatArea);
            // chatArea.first().hide();
            var chatTextDiv = chatBoxs.first().find(".jp .nH .nH").first();
            clonChatArea.focusin(function() {
                chatTextDiv.removeClass("gv").addClass("f7");
            });
            clonChatArea.focusout(function() {
                chatTextDiv.removeClass("f7").addClass("gv");
            });
            clonChatArea.on('keyup', function(event) {
                var self = this;
                //console.log(this.style.height); //make sure height it working

                if (self.scrollHeight === 38) {
                    self.style.overflowY = "hidden";
                    self.style.height = "36px";
                } else if (self.scrollHeight === 47) {
                    self.style.height = "54px";
                } else if (self.scrollHeight === 62) {
                    self.style.height = "72px";
                } else if (self.scrollHeight >= 77) {
                    self.style.height = "80px";
                    self.style.overflowY = "scroll";
                }

                if( event.keyCode === 13 && event.shiftKey ){
                    //regular, just insert a newline
                } else if (event.keyCode === 13) {
                    //grab text and modify then reinsert into real textarea
                    var chatTxt = $(this).val();
                    var chatHidden = chatBoxs.first().find(".nH textarea").first();
                    var chatEncTxt = Crypto.AES.encrypt(chatTxt, "pass"); //modify text
                    //console.log(chatEncTxt);
                    chatHidden.val(chatEncTxt);
                    chatHidden.focus();
                    chatHidden.trigger({ type : 'keypress', which : 13 }); //try to imitate the return key and send (NOT WORKING!!!)
                    // $(this).focus();
                }
            });
        }
    }
},150);
+3
source share
1 answer

It may be a little late, but if someone is interested, I succeeded by doing the following:

var e = new Event("keypress");
e.keyCode = e.which = 13;
// :mc is an example textarea id, but the OP has the code for finding that already
document.getElementById(':mc').dispatchEvent(e);
+1
source

All Articles