Skip to content

Instantly share code, notes, and snippets.

@iamvinny
Created April 8, 2024 00:15
Show Gist options
  • Save iamvinny/bfbba07e188c4649747b8fd701b56428 to your computer and use it in GitHub Desktop.
Save iamvinny/bfbba07e188c4649747b8fd701b56428 to your computer and use it in GitHub Desktop.
Cancel all sent friend requests on facebook
// Select all elements with the 'aria-label' attribute set to 'Cancel request'
const cancelButtons = Array.from(document.querySelectorAll('[aria-label="Cancel request"]'));
console.log(cancelButtons.length, 'Cancel request buttons found');
// Function to click each button with a specified interval
function clickButtonsWithInterval(buttons, interval) {
let index = 0;
const intervalId = setInterval(() => {
if (index >= buttons.length) {
clearInterval(intervalId); // Stop when all buttons are clicked
console.log('All cancel requests processed.');
} else {
console.log(`Clicking button ${index + 1}/${buttons.length}`);
buttons[index].click(); // Click the current button
index++;
}
}, interval);
}
// Execute the function with the found buttons and an interval of 300 milliseconds
clickButtonsWithInterval(cancelButtons, 300);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment