Last active
November 7, 2022 17:25
-
-
Save joshmenden/202e8b373538e38d7cf8378a7dbf7f91 to your computer and use it in GitHub Desktop.
This file contains 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
// Facebook makes it very difficult to bulk remove friends. This should help. | |
// | |
// The goal here was not to completely automate this process, but to automate | |
// like 85% of it so it would take minutes and not hours with a little bit of hand-holding. | |
// | |
// To get this to work: | |
// 1. Navigate to https://www.facebook.com/friends/list in Chrome | |
// 2. Open the inspector -> sources -> snippets | |
// 3. Dump this javascript below into a new snippet | |
// 4. If `DRY_RUN = true`, you'll see the names of your friends that *would* be deleted | |
// 5. If it's false, they'll actually be deleted (you'll watch the actions being taken on the screen) | |
// 6. Command + Enter should run the script. You'll watch the screen take the unfriending actions | |
// and see the logs in the console | |
// | |
// The hand-holding part is that you'll need to buffer up your friends by just scrolling | |
// a ton on the left side so the browser is aware of a bunch of friends (instead of the default 20). | |
// | |
// Also, from what I can tell, there's no rhyme or reason to how the list of friends is returned | |
// which makes it a little hard to dry run the thing since if you refresh your results will be different. | |
// | |
// Sometimes you'll get an error that it can't do the unfriending. Not sure why but a refresh will fix it most times. | |
// | |
// Facebook will rate limit your actions (like, every action, not just unfriending) after a certain number. | |
// Not sure what that is exactly, but it was around 1,300 unfriends for me. Not sure how long you have to wait to have access yet. | |
// | |
// This script works best if you plan to go mostly scorched earth. | |
const KEEP_NAMES = [ | |
// checked against an "include" of the full text of a person's full name, | |
// so just putting last names is the best bet here | |
] | |
const DRY_RUN = true | |
const delay = ms => new Promise(res => setTimeout(res, ms)); | |
const unfriendAll = async () => { | |
console.log('Starting new unfriend group...') | |
return new Promise(async resolve => { | |
const LISTED_FRIENDS = this.document.querySelectorAll("div[aria-label=\"More\"]"); | |
for (let i = 0; i < LISTED_FRIENDS.length; i++) { | |
const person = LISTED_FRIENDS[i] | |
const name = person.parentElement.parentElement.parentElement.parentElement.innerText.split("\n")[0] | |
if (!KEEP_NAMES.some(n => name.includes(n))) { | |
console.log(`%cDeleting ${name}`, "color:red") | |
await unfriend(person) | |
} | |
} | |
resolve() | |
}) | |
} | |
function unfriend(person) { | |
return new Promise(async resolve => { | |
if (DRY_RUN) resolve() | |
else if (!DRY_RUN) { | |
person.click() | |
await delay(200) | |
clickUnfriend() | |
await delay(200) | |
confirmUnfriend() | |
await delay(200) | |
resolve() | |
} | |
}) | |
} | |
function clickUnfriend() { | |
const menu = this.document.querySelector("div[role=menu]") | |
const menuItems = menu.querySelectorAll("div[role=menuitem]") | |
const unfriendOption = menuItems[menuItems.length - 1] | |
unfriendOption.click() | |
} | |
function confirmUnfriend() { | |
const confirm = this.document.querySelector("div[aria-label=Confirm]") | |
confirm.click() | |
} | |
const main = async () => { | |
await unfriendAll() | |
if (!DRY_RUN) location.reload() | |
} | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment