Skip to content

Instantly share code, notes, and snippets.

@atiilla
Last active August 13, 2023 16:53
Show Gist options
  • Save atiilla/22836fb508e49f16bcde333bfba916c2 to your computer and use it in GitHub Desktop.
Save atiilla/22836fb508e49f16bcde333bfba916c2 to your computer and use it in GitHub Desktop.
Unfollow user that do not follow you back on Twitter (100% working)
function twitter_unfollow_non_followers(length) {
// respect :)
const followingList = document.querySelectorAll('[data-testid^="UserCell"]');
let currentIndex = 0; // Keep track of the current index in the following list
const unfollowNext = () => {
if (currentIndex >= followingList.length || currentIndex > length) {
console.log("Unfollowing process complete.");
return;
}
const user = followingList[currentIndex];
const userButton = user.querySelector('[role="button"]');
const isUserFollowingYou = user.querySelector('[data-testid="userFollowIndicator"]');
const username = user.querySelector('a').getAttribute('href').split('/')[1];
if (!isUserFollowingYou) {
userButton.click();
setTimeout(() => {
const confirmUnfollowButton = document.querySelector('[data-testid="confirmationSheetConfirm"]');
confirmUnfollowButton.click();
console.log(`User @${username} is not following you back. Unfollowed!`);
currentIndex++; // Move to the next user
setTimeout(unfollowNext, 1000); // Wait and continue with the next user
}, 1000);
} else {
currentIndex++; // Move to the next user
unfollowNext(); // Skip to the next user directly
}
};
// Start the process
unfollowNext();
// Scroll down the page to load more users
const scrollInterval = setInterval(() => {
window.scrollBy(0, 3000); // You can adjust the scrolling distance
if (currentIndex >= followingList.length || currentIndex > length) {
clearInterval(scrollInterval);
}
}, 1000); // Adjust the scroll interval as needed
}
// Call the function with the desired number of users to check and unfollow
twitter_unfollow_non_followers(10); // Example: Check and unfollow up to 10 users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment