Skip to content

Instantly share code, notes, and snippets.

@thealphadollar
Last active June 13, 2025 09:29
Show Gist options
  • Save thealphadollar/23490d05d1b0c695ea15c5cf23732aca to your computer and use it in GitHub Desktop.
Save thealphadollar/23490d05d1b0c695ea15c5cf23732aca to your computer and use it in GitHub Desktop.
Script To Accept All Facebook Friend Requests
// If the script does not work, you may need to allow same site scripting https://stackoverflow.com/a/50902950
Facebook = {
config: {
actionDelay: 1000,
scrollDelay: 5000,
// set to -1 for no limit
maxRequestsToAccept: -1,
totalRequestsAccepted: 0,
// set string to be present in names to be accepted, leave empty to accept all
mustIncludeInName: [],
},
inspect: function (data, config) {
console.info("INFO: script initialized on the page data...");
console.debug("DEBUG: finding confirm buttons...");
var confirmDivEles = document.querySelectorAll('[aria-label="Confirm"]');
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.confirm(data, config);
} else {
console.warn("INFO: end of friend requests!");
this.complete(config);
}
},
confirm: function(data, config) {
if (data.length === 0){
console.info("INFO: Current friend request list exhausted! Scrolling for more...");
console.debug("DEBUG: scrolling to bottom in " + config.actionDelay + " ms");
setTimeout(() => this.scrollBottom(data, config), config.actionDelay);
} else {
var friendRequest = data.shift();
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!");
console.debug("DEBUG: Accepting next friend request in " + config.actionDelay);
setTimeout(() => this.confirm(data, config), config.actionDelay);
}
} else {
console.debug("DEBUG: Ignoring friend request from " + friendRequestName);
console.debug("DEBUG: Accepting next friend request in " + config.actionDelay);
setTimeout(() => this.confirm(data, config), config.actionDelay);
}
} catch (e) {
console.debug("DEBUG: Accepting next friend request in " + config.actionDelay);
setTimeout(() => this.confirm(data, config), config.actionDelay);
}
}
},
scrollBottom: function (data, config) {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
console.debug("DEBUG: waiting for scroll data to load, then finding buttons in " + config.scrollDelay + " ms");
setTimeout(() => this.inspect(data, config), config.scrollDelay);
},
complete: function (config) {
console.info('INFO: script completed after accepting ' + config.totalRequestsAccepted + ' friend requests');
}
}
Facebook.inspect([], Facebook.config);
@scott-coates
Copy link

Thanks man, impressive!

@lovkyndig
Copy link

lovkyndig commented Sep 27, 2024

In Chrome the following warning pops up when you try to copy-paste something into the console:

Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yourself. This could allow attackers to steal your identity or take control of your computer. Please type ‘allow pasting’ below and hit Enter to allow pasting.

Here is a picture of the warning:
image

To make it work, execute the following line: (If you don't do this, you will not be able to copy-paste the script into the console.)

allow pasting

After this line, when you copy-paste the script and execute it, you'll see this picture:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment