3

I was trying to make facebook autoreply msg script, here is my code

$(window).load(function(){
var a=setInterval(function(){
var e = $('.titlebarText').html();
if(!e)
{
}
else
{
$('textarea.uiTextareaAutogrow.input').focus().val('Test!');
var c = jQuery.Event("keydown");
c.which = 13; 
$('textarea.uiTextareaAutogrow.input').trigger(c);
}
}
,5000);
});


$(window).load(function(){
var q=setInterval(function(){
$('.close').click()}
,6000);
});

Everything is working perfectly but simulating enter after focusing on textarea and inserting value..

  • @Tats_innit I don't think it's same.. – Velja Janković Jul 08 '12 at 04:32
  • Okies will remove it now `:)` – Tats_innit Jul 08 '12 at 04:32
  • Not sure what you're trying to do. Simulating user input is bad and unnecessary generally. What's your expected result? Do you want to insert a line break or submit it automatically? – Fabrício Matté Jul 08 '12 at 04:33
  • 1
    Is the textarea in a form? If so you could submit that form: `$('textarea.uiTextareaAutogrow.input').closest('form').submit();` – nnnnnn Jul 08 '12 at 04:36
  • @FabrícioMatté submit it automatically, just like writing on chat. But i tested now and it wont trigger anyting, not just enter.. Don't know how to fix that.. – Velja Janković Jul 08 '12 at 04:36
  • +1 @nnnnnn, [`.submit()`](http://api.jquery.com/submit/) is the way to go. (I'm checking if there's any form to be submitted in the facebook api) – Fabrício Matté Jul 08 '12 at 04:38
  • @nnnnnn nice one, but it's submiting form which is posting on wall, and it's working, but not on chat.. – Velja Janković Jul 08 '12 at 04:39
  • Try with `textarea.uiTextareaAutogrow.MessagingComposerBody` for the chat (or just take out the `.input` class from the selector) – Fabrício Matté Jul 08 '12 at 04:43
  • @FabrícioMatté without .input it's sending me to https://www.facebook.com/ajax/ufi/modify.php and first one is not working at all. looks like there is no form for chat, maybe – Velja Janković Jul 08 '12 at 04:47
  • Yeah, I posted that after inspecting FB's markup. It's really messy to find anything useful, at this rate you'll most likely have to call the function which submits the chat message. – Fabrício Matté Jul 08 '12 at 04:51

1 Answers1

2

Your selector looks strange. textarea.uiTextareaAutogrow.input says "the textarea with class uiTextareaAutogrow and class input"--do you really have a textarea tag with the class input?

You could try this, provided your selector is correct:

var e = $.Event('keydown', { keyCode: 13 });
$('textarea.uiTextareaAutogrow.input').trigger(e);
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222