Created
March 10, 2025 09:55
-
-
Save fahdi/5df7cf66b4620535372bcb0c13c8d20d to your computer and use it in GitHub Desktop.
I take no responsibility whatsoever for anything this script does. Use at your own risk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Go to : https://www.facebook.com/friends/list | |
// copy and paste the following code into console. | |
// ENJOY | |
// Configuration | |
const MAX_UNFRIENDS_PER_DAY = 500; | |
const DELAY_BETWEEN_ACTIONS = 2000; // 2 seconds delay between actions | |
// Function to get the unfriend buttons | |
function getUnfriendButtons() { | |
// Find all "More" buttons (three dots) in the friends list | |
const moreButtons = Array.from(document.querySelectorAll('div[aria-label="More"]')); | |
return moreButtons; | |
} | |
// Function to click on a button with a delay | |
function clickWithDelay(button) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
button.click(); | |
resolve(); | |
}, DELAY_BETWEEN_ACTIONS); | |
}); | |
} | |
// Function to find and click the Unfriend option in the dropdown menu | |
async function clickUnfriendOption() { | |
// Wait for the dropdown menu to appear | |
await new Promise(resolve => setTimeout(resolve, 500)); | |
// Look for the Unfriend option | |
const menuItems = Array.from(document.querySelectorAll('div[role="menuitem"]')); | |
const unfriendButton = menuItems.find(item => | |
item.textContent.includes('Unfriend') || | |
item.textContent.includes('Remove friend') | |
); | |
if (unfriendButton) { | |
await clickWithDelay(unfriendButton); | |
// Wait for confirmation dialog and click Confirm | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
const confirmButtons = Array.from(document.querySelectorAll('div[role="button"]')); | |
const confirmButton = confirmButtons.find(button => | |
button.textContent.includes('Confirm') || | |
button.textContent.includes('Remove') | |
); | |
if (confirmButton) { | |
await clickWithDelay(confirmButton); | |
return true; | |
} | |
} | |
return false; | |
} | |
// Main function to remove friends | |
async function removeFriends() { | |
let unfriendCount = 0; | |
let scrollCount = 0; | |
while (unfriendCount < MAX_UNFRIENDS_PER_DAY) { | |
const buttons = getUnfriendButtons(); | |
if (buttons.length === 0) { | |
// If no buttons are found, scroll down to load more friends | |
window.scrollTo(0, document.body.scrollHeight); | |
scrollCount++; | |
// Wait for content to load after scrolling | |
await new Promise(resolve => setTimeout(resolve, 2000)); | |
// If we've scrolled several times without finding buttons, break | |
if (scrollCount > 5) { | |
console.log("No more friend entries found after scrolling. Stopping."); | |
break; | |
} | |
continue; | |
} | |
// Reset scroll count since we found buttons | |
scrollCount = 0; | |
// Process the first button in the list | |
await clickWithDelay(buttons[0]); | |
const removed = await clickUnfriendOption(); | |
if (removed) { | |
unfriendCount++; | |
console.log(`Removed friend ${unfriendCount} of ${MAX_UNFRIENDS_PER_DAY}`); | |
// Wait a bit longer between successful removals | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
} | |
// If we've reached the limit, exit | |
if (unfriendCount >= MAX_UNFRIENDS_PER_DAY) { | |
console.log(`Daily limit of ${MAX_UNFRIENDS_PER_DAY} reached. Stopping.`); | |
break; | |
} | |
} | |
console.log(`Removal process completed. Removed ${unfriendCount} friends.`); | |
} | |
// Start the process | |
console.log("Starting friend removal process..."); | |
console.log(`Will remove up to ${MAX_UNFRIENDS_PER_DAY} friends with ${DELAY_BETWEEN_ACTIONS}ms delay between actions.`); | |
removeFriends(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment