Open In App

Auto comment on a facebook post using JavaScript

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to learn how to comment automatically on a Facebook post. You can use this method to wish your friends a happy birthday or just comment on anything. It is useful when you want to comment a number of times on a post. You just need to specify the count and message that will be automatically commented on a time interval. Also, you don’t need to install anything for this method to work.

Approach:

  1. Initialize count and message value.
  2. Then define an interval function that will be called each time.
  3. Make an input variable that points to the input field of the comment section.
  4. Make a submit variable that points to the comment button.
  5. Since the comment button is disabled by default, so first enable it.
  6. Set the message to be written in input.
  7. Click on the submit.
  8. Decrement the count.
  9. If the count becomes zero, then clear the interval function.
  10. Set the time interval of 10000ms, which means the function will be called after every 10 seconds.

Below are the steps:

  • Go to the Facebook page using m.facebook.com
  • Sign in and open any post.
  • Open developer mode in Chrome by pressing Ctrl+Shift+I
  • Navigate to the console.
  • Now, run the below script.

javascript




var count = 100;
var message = "Hi";
var loop = setInterval(function(){
    var input = document.getElementsByName("comment_text")[0];
    var submit = document.querySelector('button[type="submit"]');
    submit.disabled = false;
    input.value = message;
    submit.click();
    count -= 1;
    if(count == 0)
    {
        clearInterval(loop);
    }
}, 10000);


Output:

Output

Note: Please ensure that there is a stable internet connection available so that the script runs smoothly. Also, ensure to visit Facebook with m.facebook.com, not www.facebook.com because this script works on the mobile version of Facebook only.

Note: This tutorial is for educational purpose only, please don’t use it for disturbing anyone or any unethical way.


Last Updated : 24 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads