Skip to content

Instantly share code, notes, and snippets.

@anned20
Last active April 10, 2023 12:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anned20/57a7c00303d1dab3408613a64c7842d0 to your computer and use it in GitHub Desktop.
Facebook unfollower and refollower

Facebook unfollower and refollower

Want to unfollow every friend you have on Facebook to reduce the clutter and regain focus?

Or unfollowed a lot of your friends on Facebook? Want to follow them again and not click 9 million times on small buttons?

This script can do it automatically!

Requirements

  • The script is made for Facebook in the English (US) language. If you use a different language, it probably won't work. You can try setting the language to the English (US) language temporarily.

Usage

  1. Go to https://www.facebook.com/friends/list
  2. In the list on the left, make sure you scroll to the bottom to load the full list of friends.
  3. Open your browser devtools https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/What_are_browser_developer_tools#how_to_open_the_devtools_in_your_browser
  4. Paste the code in script.js in the console of the devtools.
  5. Wait until you see no more menus pop up automatically.

Disclaimer

Using the browser devtools with scripts from external sources like this one is frowned upon, but it is the best way for this issue.

I do not intend to steal any data or harm any users, that is why the script is open source and readable for everyone.

This is also not the cleanest code ever. It was made in a hurry, does the job and it's a one-off script

(async () => {
sleep = ms => new Promise(r => setTimeout(r, ms));
mores = Array.from(document.querySelectorAll('[aria-label="All friends"] [aria-label="More"]'));
for (more of mores) {
await new Promise(async (resolve, reject) => {
more.click();
await sleep(10);
more.scrollIntoView();
const follow = Array.from(document.querySelectorAll('[role="menuitem"]'))
?.find(el => el.textContent.contains('See posts from'));
if (!follow) {
more.click();
return resolve();
}
follow.click();
await sleep(2000);
return resolve();
});
}
})()
(async () => {
sleep = ms => new Promise(r => setTimeout(r, ms));
mores = Array.from(document.querySelectorAll('[aria-label="All friends"] [aria-label="More"]'));
for (more of mores) {
await new Promise(async (resolve, reject) => {
more.click();
await sleep(10);
more.scrollIntoView();
const unfollow = Array.from(document.querySelectorAll('[role="menuitem"]'))
?.find(el => el.textContent.contains('Stop seeing posts but stay friends.'));
if (!unfollow) {
more.click();
return resolve();
}
unfollow.click();
await sleep(2000);
return resolve();
});
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment