简体   繁体   中英

Fire Enter-Keypress event in contenteditable chat div

I'm trying to automatically send a motivational message to a friend who's studying for an exam over hangouts.
I'm using the hangouts app at https://hangouts.google.com/ (using the gmail site wouldn't allow me to access the DOM of the iframe because of the Same-Origin-Policy ) and am already able to set the value of the chatbox-div:

var ifrm = document.getElementById('iframeid'); // changes after reload
var doc = ifrm.contentDocument;
var chat = doc.getElementById('chatdivid'); // also changes
chat.innerHTML = "go kathi go!";

This works already.
My problem now is: how do I either send the appropriate keypress to that div or fire the event/callback directly?

I already tried to send an enter-keypress like this:

var enterPress = new KeyboardEvent('keypress', {'key': 'Enter'});
chat.dispatchEvent(enterPress);

But this only deletes the faint informational "Send a message" message and doesn't submit the chat message.

I didn't find solution using JS for your problem, but I think (if you also didn't find it) you can use macroses.

I would use Firefox + iMacros . Chrome has this extension too, but it's worse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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