Last active
November 18, 2019 07:11
-
-
Save kiriappeee/03f0f13dd7dad57d9e2d99b2b7d2d2dc to your computer and use it in GitHub Desktop.
Unfollow friends fb
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
//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); | |
} | |
} | |
} |
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
Worked like a charm for me on Chrome. One thing though, I tested running this on the news feed (home) page; it didn't work prompted me about element not found. Then I navigated to the profile page and ran, it worked. Just FYI.
Thanks for this.