最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Sending a chat message in Facebook using Javascript using the browser console - Stack Overflow

programmeradmin5浏览0评论

I'm trying to send a chat message in Facebook using Javascript, but keep getting an error message. Either it being TypeError: Object #<NodeList> has no method 'WHATEVERIPUTHERE'

Basically o = the chat text area.

The o.WHATEVERIPUTHERE("Hello!") is what I'm trying to do (setting a value for the text area, and sending it)

This is what I have tried:

var o = document.getElementsByClassName("uiTextareaAutogrow _552m");
o.WHATEVERIPUTHERE("Hello!");

I'm trying to send a chat message in Facebook using Javascript, but keep getting an error message. Either it being TypeError: Object #<NodeList> has no method 'WHATEVERIPUTHERE'

Basically o = the chat text area.

The o.WHATEVERIPUTHERE("Hello!") is what I'm trying to do (setting a value for the text area, and sending it)

This is what I have tried:

var o = document.getElementsByClassName("uiTextareaAutogrow _552m");
o.WHATEVERIPUTHERE("Hello!");
Share Improve this question edited Aug 22, 2013 at 5:13 Ionică Bizău 114k94 gold badges310 silver badges487 bronze badges asked Aug 22, 2013 at 4:28 Jer DevJer Dev 552 silver badges8 bronze badges 1
  • 3 If the answers below helped you out, please be sure to upvote and choose an accepted answer. Otherwise, are you still having the issue? Did you solve it yourself? – user3373470 Commented Aug 19, 2015 at 17:44
Add a ment  | 

3 Answers 3

Reset to default 5

document.getElementsByClassName returns an array of elements. In this case they will have same number with the chat boxes opened.

I wrote it in pure Javascript:

var o = document.getElementsByClassName("uiTextareaAutogrow _552m");

// set the chat textbox
var chatTextBox = o[0];

// set the message value
chatTextBox.value = "Hello";

// create a keydown event    
var e = new Event("keydown");

// it has to simulate the Enter press (key code is 13)
e.keyCode = 13;

// trigger it
chatTextBox.dispatchEvent(e);

Awesome...it's working for me. Below is my code

var o = document.getElementsByClassName("uiTextareaNoResize uiTextareaAutogrow _1rv");

// set the chat textbox
var chatTextBox = o[0];

// set the message value
chatTextBox.value = "Hello";

// create a keydown event    
var e = new Event("keydown");

// it has to simulate the Enter press (key code is 13)
e.keyCode = 13;

// trigger it
chatTextBox.dispatchEvent(e);

As of 31-12-2016 the structure has changed... I haven't achieved it pletely because I'm stuck with the sending part. Because for some reason when I'm entering the dynamic value, FB is blocking me from pressing Enter or back..The behaviour is weird.

Here's my piece of code [Not plete]

//Open up all the chat window visible on the chat panel
STEP 1:

javascript:var inputs = document.getElementsByClassName('_55ln'); 
for(var i=0; i<inputs.length ; i++) { 
inputs[i].click(); 
break; //testing purpose
}


STEP 2:

javascript:var item = document.getElementsByClassName('fbNubFlyout  fbDockChatTabFlyout uiContextualLayerParent');

for(var k=0;k<item.length;k++){
var child = item[k].getElementsByClassName('_1p1t');
item[k].removeChild(child);

var send = item[k].getElementsByClassName('_1mf _1mj'); 
console.log(send);
for(var j=0;j<send.length; j++){
var attr = send[j].getAttribute('data-offset-key');
var new_content = '<span data-offset-key="'+attr+'"><span data-text="true">HI!! Testing</span></span>';
send[j].innerHTML=new_content;
}

}
发布评论

评论列表(0)

  1. 暂无评论