Skip to content

Instantly share code, notes, and snippets.

@Chematronix
Forked from thealphadollar/fb_accept_friends.js
Last active January 14, 2023 00:16
Show Gist options
  • Save Chematronix/2d2f73e3b353414b58ff527d5d96d06d to your computer and use it in GitHub Desktop.
Save Chematronix/2d2f73e3b353414b58ff527d5d96d06d to your computer and use it in GitHub Desktop.
Script To Accept All Facebook Friend Requests
// Open Facebook, log in, and go to https://www.facebook.com/friends/requests/.
// Please open the developer console of your browser in the Tools menu, pressing F12 or such.
// Copy the entire script into the console and hit enter.
// Do not close or refresh the browser tab unless you want the script to stop abruptly.
// If the script does not work, you may need to allow same site scripting https://stackoverflow.com/a/50902950
Facebook = {
config: {
confirmText: "Confirm",
actionDelay: 2000,
// set to -1 for no limit
maxRequestsToAccept: 1000,
totalRequestsAccepted: 0,
// set string to be present in names to be accepted, leave empty to accept all
mustIncludeInName: [],
},
findFriendConfirmButtons: function (data, config) {
console.info("INFO: finding confirm buttons...");
var confirmDivEles = document.querySelectorAll('[aria-label^="'+ config.confirmText +'"]');
data = [];
for (var i = 0; i < confirmDivEles.length; i++) {
if (confirmDivEles[i].getAttribute("aria-disabled") == null && confirmDivEles[i].innerText.includes("Confirm")) {
data.push(confirmDivEles[i]);
}
}
var totalRows = data.length;
console.debug("DEBUG: total confirm buttons found on page are " + totalRows);
if (totalRows > 0) {
this.confirmFriendRequest(data, config);
} else {
console.warn("INFO: end of friend requests!");
this.complete(config);
}
},
confirmFriendRequest: function(data, config) {
if (data.length === 0){
console.info("INFO: Current friend request list exhausted. Finding more...");
setTimeout(() => this.findFriendConfirmButtons(data, config), config.actionDelay * Math.random() * 2);
} else {
var friendRequest = data.shift();
friendRequest.scrollIntoView({ behavior: "smooth", block: "start" });
try {
var friendRequestName = friendRequest.parentElement.parentElement.parentElement.parentElement.parentElement.textContent.toLowerCase().split(" ")[0];
if (config.mustIncludeInName.length <= 0 || config.mustIncludeInName.some(x => friendRequestName.match(x.toLowerCase()))) {
friendRequest.click();
config.totalRequestsAccepted += 1;
config.maxRequestsToAccept -= 1;
if (config.maxRequestsToAccept === 0) {
this.complete(config);
} else {
console.info("INFO: " + config.totalRequestsAccepted + " friend requests accepted!");
setTimeout(() => this.confirmFriendRequest(data, config), config.actionDelay * Math.random() * 2);
}
} else {
console.debug("DEBUG: Ignoring friend request from " + friendRequestName);
setTimeout(() => this.confirmFriendRequest(data, config), config.actionDelay * Math.random() * 2);
}
} catch (e) {
setTimeout(() => this.confirmFriendRequest(data, config), config.actionDelay * Math.random() * 2);
}
}
},
complete: function (config) {
console.info('INFO: script completed after accepting ' + config.totalRequestsAccepted + ' friend requests');
}
}
Facebook.findFriendConfirmButtons([], Facebook.config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment