Skip to content

Facebook Script to Click on All Loaded Like Buttons

Published: at 09:08 PM

Here’s a lightweight JavaScript snippet to programmatically click all the visible “Like” buttons on Facebook. It’s a fun script I made to execute on my brother’s profile for two reasons: 1. I have to like all his posts and 2. to trouble him a bit! :D

Disclaimer: Automating actions on social media platforms can violate their terms of service. It’s essential to use such scripts responsibly and ethically. Always ensure you’re complying with the platform’s rules and regulations.

Understanding the Script:

The provided JavaScript code is designed to automate clicking on all “Like” buttons that are currently loaded on a Facebook page. Here’s a breakdown of how it works:

  1. Creating a Mouse Click Event:

    • A new MouseEvent object is created, simulating a real mouse click.
    • Key properties are set:
      • view: The window object, indicating the event’s target.
      • bubbles: true to allow the event to bubble up the DOM.
      • cancelable: true to allow the event to be canceled.
  2. Identifying “Like” Buttons:

    • The getElementsByClassName() method is used to locate all elements with the class name UFILikeLink, which typically corresponds to Facebook’s “Like” buttons.
  3. Simulating Clicks:

    • A for loop iterates through the list of found buttons.
    • For each button, the dispatchEvent() method is used to trigger the simulated mouse click event.
    • The console.log(res) line logs the result of the dispatchEvent() operation, which can be useful for debugging purposes.

Potential Use Cases and Ethical Considerations:

While this script can be used to automate “Like” clicks, it’s important to consider the ethical implications and potential misuse:

Responsible Use:

If you choose to use such scripts, it’s crucial to do so responsibly and ethically. Consider the following:

The Script

var mc = new MouseEvent("click", {
  view: window,
  bubbles: true,
  cancelable: true,
});
var btns = document.getElementsByClassName("UFILikeLink");
for (var i = 0; i < btns.length; i++) {
  var res = btns[i].dispatchEvent(mc);
  console.log(res);
}

Additional Use Cases

The logic can be adapted for other interactive elements on Facebook, such as:

Adding Suggested Friends: Target buttons for friend requests by replacing the UFILikeLink class with the appropriate class name for those elements.

var btns = document.getElementsByClassName("ClassForFriendRequestButtons");
for (var i = 0; i < btns.length; i++) {
  btns[i].dispatchEvent(mc);
}

Previous Post
Using Diskpart to Manage Partitions
Next Post
Test Credit Card Numbers for Payment Processing