Created
June 17, 2025 12:09
-
-
Save twobob/90ebb8f08cfc445ac0005d761522dc04 to your computer and use it in GitHub Desktop.
Unfollow all twitter users. one by one. it will unfollow all visible users, scroll to the bottom to load the next batch, and repeat this process until no more "Following" buttons are found.
This file contains hidden or 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
Instructions | |
Navigate to your "Following" list on X.com (e.g., https://x.com/your_username/following). | |
Open your browser's developer console (press F12 or Ctrl+Shift+I / Cmd+Opt+I). | |
Copy the entire script from the block below, paste it into the console, and press Enter. | |
The script will now run continuously. You can leave the browser tab open while it works. | |
It will log its progress and stop automatically when the list is exhausted. | |
Disclaimer: This script performs actions on your behalf. | |
Running automation scripts on social media platforms may be against their terms of service and could pose a risk to your account. | |
Use it responsibly and at your own risk. |
This file contains hidden or 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
/** | |
* @name Twitter/X Automated Unfollow Script | |
* @description This script automates unfollowing users from the "Following" list page. | |
* It continuously processes users, scrolls down to load more, and repeats until the list is exhausted. | |
* @version 2.0 | |
* @author Gemini | |
* @runInBrowser | |
* | |
* @instructions | |
* 1. Navigate to your "Following" list on X.com (e.g., https://x.com/your_username/following). | |
* 2. Open the browser's developer console (F12 or Ctrl+Shift+I/Cmd+Opt+I). | |
* 3. Copy and paste this entire script into the console and press Enter. | |
* 4. The script will run automatically. Keep the tab open to monitor its progress. | |
*/ | |
(async function() { | |
// --- Configuration --- | |
// Delay between each unfollow action to avoid rate-limiting. 2000ms (2s) is a safe starting point. | |
const unfollowDelay = 1000; | |
// Delay after scrolling to allow the page to load new users. | |
const scrollDelay = 3000; | |
// Time to wait for the confirmation dialog to appear after clicking "Following". | |
const dialogWaitTime = 500; | |
// --------------------- | |
let totalUnfollowed = 0; | |
let consecutiveFails = 0; | |
const maxConsecutiveFails = 3; // Stops if it can't find new users after 3 attempts. | |
console.log("--- Starting Automated Unfollow Script ---"); | |
console.log(`Configuration: Unfollow Delay: ${unfollowDelay}ms, Scroll Delay: ${scrollDelay}ms`); | |
// Main loop to continuously find and unfollow users. | |
while (true) { | |
// Select all "Following" buttons currently loaded in the DOM. | |
const buttons = document.querySelectorAll('button[data-testid$="-unfollow"]'); | |
if (buttons.length === 0) { | |
consecutiveFails++; | |
console.log(`No 'Following' buttons found. Attempting to scroll... (${consecutiveFails}/${maxConsecutiveFails})`); | |
if (consecutiveFails >= maxConsecutiveFails) { | |
console.log("No new users found after multiple scroll attempts. The list is likely complete."); | |
break; | |
} | |
// Scroll down to see if more users load. | |
const oldScrollHeight = document.body.scrollHeight; | |
window.scrollTo(0, oldScrollHeight); | |
await new Promise(resolve => setTimeout(resolve, scrollDelay)); | |
const newScrollHeight = document.body.scrollHeight; | |
// If the page height didn't change, we've reached the bottom. | |
if (newScrollHeight === oldScrollHeight) { | |
console.log("Page end reached. No more content to load."); | |
break; | |
} | |
// If new content loaded, continue the loop to process it. | |
continue; | |
} | |
// Reset the failure counter as we have found new buttons. | |
consecutiveFails = 0; | |
console.log(`Found a batch of ${buttons.length} users to process.`); | |
// Loop through the found buttons for this batch. | |
for (const button of buttons) { | |
const userHandle = button.getAttribute('aria-label') || 'Unknown User'; | |
try { | |
// Ensure the button is visible before interacting with it. | |
button.scrollIntoView({ behavior: 'smooth', block: 'center' }); | |
await new Promise(resolve => setTimeout(resolve, 300)); // Short delay for scroll animation | |
// 1. Click the initial "Following" button. | |
button.click(); | |
// 2. Wait for the confirmation dialog to appear. | |
await new Promise(resolve => setTimeout(resolve, dialogWaitTime)); | |
// 3. Click the final "Unfollow" button in the dialog. | |
const confirmButton = document.querySelector('[data-testid="confirmationSheetConfirm"]'); | |
if (confirmButton) { | |
confirmButton.click(); | |
totalUnfollowed++; | |
console.log(`(${totalUnfollowed}) Unfollowed: ${userHandle}`); | |
} else { | |
console.error(`Could not find confirmation dialog for ${userHandle}. Skipping.`); | |
// Press "Escape" to try to close any unexpected modal that may have appeared. | |
document.body.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })); | |
} | |
// 4. Wait before processing the next person. | |
await new Promise(resolve => setTimeout(resolve, unfollowDelay)); | |
} catch (error) { | |
console.error(`An error occurred while trying to unfollow ${userHandle}:`, error); | |
} | |
} | |
} | |
console.log(`--- Script Complete ---`); | |
console.log(`Total users unfollowed in this session: ${totalUnfollowed}`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment