Skip to content

Instantly share code, notes, and snippets.

@dnalob
Forked from oatycreates/twitter-unfollow-all.js
Created November 5, 2022 12:57
Show Gist options
  • Save dnalob/fac7d2a7d313feb337bb2234f606af2e to your computer and use it in GitHub Desktop.
Save dnalob/fac7d2a7d313feb337bb2234f606af2e to your computer and use it in GitHub Desktop.
Unfollow All for Twitter
/*
* Unfollow All for Twitter
*
* Go to https://twitter.com/<YourUserName>/following and run the
* below code in the console to gradually unfollow all accounts
* you are following, this should play nice with any rate limiting.
* Built on current Firefox (2021-08-26) though may work for others.
*
* Author: https://twitter.com/OatyCreates
* Copyright 2021-Present @oatycreates
*/
toUnfollow = [];
setInterval(() => {
if (toUnfollow.length === 0) {
// Ran out of data, fetch new
// NOTE - This uses the accessibility label text and will need to be updated for other languages
toUnfollow = Array.from(document.querySelectorAll('[aria-label^="Following"]'));
}
if (toUnfollow.length >= 0) {
// Unfollow one by one
unfollowPerson(toUnfollow.shift());
}
if (toUnfollow.length === 0) {
// Finished data, bring new elements into view
window.scrollTo(0, document.body.scrollHeight); // Scroll to load fresh data over time
}
}, 500); // Load data or unfollow an account every interval
unfollowPerson = (unfollowBtn) => {
unfollowBtn.click();
// There is a follow-up confirmation prompt so click that too
// NOTE - This ID may change, it is trying to find the button element for the unfollow confirmation
unfollowConfirmBtns = document.querySelectorAll('[data-testid="confirmationSheetConfirm"]');
unfollowConfirmBtns.forEach((btn) => btn.click());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment