Skip to content

Instantly share code, notes, and snippets.

@thealphadollar
Last active March 29, 2024 19:36
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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);
@thealphadollar
Copy link
Author

thealphadollar commented Jul 16, 2020

What is this?

Have you ever felt like there was a way to accept all your Facebook friend requests automatically? That's where this script fits in.

The script, once runs (instructions below), works in the background on the page and keeps on accepting friend requests on the page as long as either it meets maximum requests specified by you or there are no more friend requests. The script has an adequate amount of delay placed between actions so you are not banned 😄

How to use the above script?

  • Open Facebook, log in, and go to https://www.facebook.com/friends/requests/.
  • Please open the developer console of your browser following the instructions here for your browser.
  • Copy the entire above script and paste it into the console and hit enter.
  • Keep scrolling the left side bar of friend requests to keep accepting requests.
  • Do not close or refresh the browser tab unless you want the script to stop abruptly.

You'll see that friend requests are being accepted now after delays set in the config of the above file. If you want to limit the number of requests to be accepted, please update maxRequestsToAccept above to the desired number of requests.

When does the script stop gracefully?

  • When there are no requests to accept.
  • When the number of max requests (if specified) is reached.

What to configure?

If it is taking too long or you are on a very fast internet connection, you can lower the delays between each action since elements will be loading faster for you. Below is an explanation of what each of the configuration item does:

  • scrollDelay: specifies the wait in milliseconds after scrolling page to the bottom to load more friend requests.
  • actionDelay: specifies the delay in milliseconds between each click of the confirm button.
  • maxRequestsToAccept: set to a positive number to limit the number of friend requests to be accepted to that numbers; a negative number leads to infinite friend requests being accepted (not really).
  • totalRequestsAccepted: stores the number of total requests accepted (displayed when the script stops gracefully) and is not to be changed and should remain 0.
  • mustIncludeInName: store the array of strings - any one of which should be present in the name of the friend request to be accepted. If the array is empty, all friend requests are accepted.

Acknowledgement

This script takes inspiration from the LinkedIn AutoConnect script (https://gist.github.com/thealphadollar/7c0ee76664cbd28aecc1bd235f0202fd).

TODO

  • Automate scrolling the friend requests left side bar.

@scott-coates
Copy link

Thanks man, impressive!

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