Skip to content

Instantly share code, notes, and snippets.

@kiriappeee
Last active November 18, 2019 07:11
Show Gist options
  • Save kiriappeee/03f0f13dd7dad57d9e2d99b2b7d2d2dc to your computer and use it in GitHub Desktop.
Save kiriappeee/03f0f13dd7dad57d9e2d99b2b7d2d2dc to your computer and use it in GitHub Desktop.
Unfollow friends fb
//a script to unfollow everyone on fb
//copy everything below into the console and when you are ready,
//type unfollowEveryone(); into the JS console and hit enter.
//Not going to include actually running the command in this script.
//Running the script is ultimately your choice, and I bear no responsibility
//for this script unfollowing all pages, friends, groups, etc that you follow
//on FB and I make no guarantees about its correctness beyond saying
//it worked for me.
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
}
async function unfollowEveryone(){
while (true){
document.getElementById('userNavigationLabel').click();
console.log('Waiting to ensure the user navigation menu opens');
await sleep(3000);
var nfPreferenceLink=document.querySelector('a[ajaxify="/feed_preferences/dialog/"]');
nfPreferenceLink.click();
console.log("waiting for stuff to load");
await sleep((Math.random()*(200))+3000);
var nfPreferenceList=document.querySelectorAll('div._2rr4._1hzp');
var unfollowDiv=nfPreferenceList[1];
unfollowDiv.querySelector('div[role="button"]').click();
console.log("waiting for people to load");
await sleep((Math.random()*(300))+4900);
var unfollowableList=unfollowDiv.querySelectorAll('div._43x8._43xa');
if (unfollowableList.length==0){
console.log("No more people to unfollow");
unfollowDiv.parentElement.querySelector('a.layerCancel').click();
await sleep((Math.random()*(2000))+1000);
break;
}
else{
for (var i=0; i<unfollowableList.length; i++){
console.log("unfollowing");
unfollowableList[i].querySelector('div[role="button"]').click();
await sleep((Math.random()*(200))+1000);
}
console.log("done");
unfollowDiv.parentElement.querySelector('a.layerCancel').click();
await sleep((Math.random()*(200))+1000);
}
}
}
@kiriappeee
Copy link
Author

Nice! Thanks for that @kisanme. There do seem to be some weird moments where the element goes missing. Not entirely sure what to do about that. Will probably put some better error handling for these cases to just say "hmm couldn't find element, please refresh"

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