Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created June 24, 2025 15:00
Show Gist options
  • Save Archie22is/6b596ecdab9450d374a179863c88dbc7 to your computer and use it in GitHub Desktop.
Save Archie22is/6b596ecdab9450d374a179863c88dbc7 to your computer and use it in GitHub Desktop.
IG Unfollow Script
// Instagram Unfollow Non-Followers Script
// Run this in your browser console on Instagram web (instagram.com)
// IMPORTANT: Use responsibly and respect Instagram's rate limits
// This script adds delays to avoid triggering Instagram's anti-spam measures
async function unfollowNonFollowers() {
console.log('πŸš€ Starting Instagram unfollow process...');
// Configuration
const DELAY_BETWEEN_ACTIONS = 3000; // 3 seconds between unfollows
const MAX_UNFOLLOWS_PER_SESSION = 20; // Limit to avoid rate limiting
let unfollowCount = 0;
let nonFollowers = [];
// Helper function to wait
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// Function to scroll and load more users
async function scrollToLoadMore(container) {
const scrollHeight = container.scrollHeight;
container.scrollTo(0, scrollHeight);
await sleep(2000);
return container.scrollHeight > scrollHeight;
}
// Function to get following list
async function getFollowingList() {
console.log('πŸ“‹ Getting your following list...');
// Go to your profile first
window.location.href = `${window.location.origin}/${window.location.pathname.split('/')[1]}`;
await sleep(3000);
// Click on following count
const followingLink = document.querySelector('a[href*="/following/"]');
if (!followingLink) {
throw new Error('Could not find following link. Make sure you are on your profile page.');
}
followingLink.click();
await sleep(2000);
const followingModal = document.querySelector('div[role="dialog"]');
if (!followingModal) {
throw new Error('Following modal did not open');
}
const followingContainer = followingModal.querySelector('div[style*="overflow"]');
// Scroll to load all following
console.log('πŸ“œ Loading all following users...');
let hasMore = true;
while (hasMore) {
hasMore = await scrollToLoadMore(followingContainer);
}
// Extract following usernames
const followingElements = followingModal.querySelectorAll('a[role="link"]');
const following = Array.from(followingElements)
.map(el => el.getAttribute('href'))
.filter(href => href && href.startsWith('/') && href.length > 1)
.map(href => href.substring(1).replace('/', ''))
.filter(username => username && !username.includes('?'));
console.log(`βœ… Found ${following.length} users you're following`);
return following;
}
// Function to get followers list
async function getFollowersList() {
console.log('πŸ“‹ Getting your followers list...');
// Close following modal and open followers
document.querySelector('svg[aria-label="Close"]')?.parentElement?.click();
await sleep(1000);
const followersLink = document.querySelector('a[href*="/followers/"]');
if (!followersLink) {
throw new Error('Could not find followers link');
}
followersLink.click();
await sleep(2000);
const followersModal = document.querySelector('div[role="dialog"]');
const followersContainer = followersModal.querySelector('div[style*="overflow"]');
// Scroll to load all followers
console.log('πŸ“œ Loading all followers...');
let hasMore = true;
while (hasMore) {
hasMore = await scrollToLoadMore(followersContainer);
}
// Extract follower usernames
const followerElements = followersModal.querySelectorAll('a[role="link"]');
const followers = Array.from(followerElements)
.map(el => el.getAttribute('href'))
.filter(href => href && href.startsWith('/') && href.length > 1)
.map(href => href.substring(1).replace('/', ''))
.filter(username => username && !username.includes('?'));
console.log(`βœ… Found ${followers.length} followers`);
return followers;
}
// Function to unfollow a user
async function unfollowUser(username) {
try {
// Go to user's profile
window.location.href = `${window.location.origin}/${username}`;
await sleep(3000);
// Find and click the Following button
const followingButton = Array.from(document.querySelectorAll('button'))
.find(btn => btn.textContent.includes('Following'));
if (!followingButton) {
console.log(`❌ Could not find Following button for ${username}`);
return false;
}
followingButton.click();
await sleep(1000);
// Confirm unfollow
const unfollowConfirm = Array.from(document.querySelectorAll('button'))
.find(btn => btn.textContent.includes('Unfollow'));
if (unfollowConfirm) {
unfollowConfirm.click();
console.log(`βœ… Unfollowed ${username}`);
return true;
} else {
console.log(`❌ Could not confirm unfollow for ${username}`);
return false;
}
} catch (error) {
console.log(`❌ Error unfollowing ${username}:`, error);
return false;
}
}
try {
// Get both lists
const followingList = await getFollowingList();
const followersList = await getFollowersList();
// Find non-followers
nonFollowers = followingList.filter(user => !followersList.includes(user));
console.log(`🎯 Found ${nonFollowers.length} users who don't follow you back:`);
console.log(nonFollowers);
// Close modal
document.querySelector('svg[aria-label="Close"]')?.parentElement?.click();
await sleep(1000);
// Ask for confirmation
const confirmUnfollow = confirm(
`Found ${nonFollowers.length} users who don't follow you back.\n\n` +
`This will unfollow up to ${MAX_UNFOLLOWS_PER_SESSION} users with ${DELAY_BETWEEN_ACTIONS/1000}s delays.\n\n` +
'Continue?'
);
if (!confirmUnfollow) {
console.log('❌ Operation cancelled by user');
return;
}
// Start unfollowing process
console.log('πŸš€ Starting unfollow process...');
for (const username of nonFollowers.slice(0, MAX_UNFOLLOWS_PER_SESSION)) {
if (unfollowCount >= MAX_UNFOLLOWS_PER_SESSION) {
console.log(`⏹️ Reached maximum unfollows per session (${MAX_UNFOLLOWS_PER_SESSION})`);
break;
}
console.log(`πŸ”„ Processing ${username} (${unfollowCount + 1}/${Math.min(nonFollowers.length, MAX_UNFOLLOWS_PER_SESSION)})`);
const success = await unfollowUser(username);
if (success) {
unfollowCount++;
}
// Wait between actions to avoid rate limits
if (unfollowCount < MAX_UNFOLLOWS_PER_SESSION) {
console.log(`⏳ Waiting ${DELAY_BETWEEN_ACTIONS/1000} seconds...`);
await sleep(DELAY_BETWEEN_ACTIONS);
}
}
console.log(`πŸŽ‰ Completed! Unfollowed ${unfollowCount} users.`);
if (nonFollowers.length > MAX_UNFOLLOWS_PER_SESSION) {
console.log(`πŸ“ ${nonFollowers.length - MAX_UNFOLLOWS_PER_SESSION} users remaining. Run the script again later to continue.`);
}
} catch (error) {
console.error('❌ Script error:', error);
console.log('πŸ”§ Make sure you are logged into Instagram and on your profile page');
}
}
// Instructions for use
console.log(`
🎯 INSTAGRAM UNFOLLOW NON-FOLLOWERS SCRIPT
==========================================
INSTRUCTIONS:
1. Go to instagram.com and log in
2. Navigate to your profile page
3. Open browser console (F12)
4. Paste this entire script
5. Run: unfollowNonFollowers()
SAFETY FEATURES:
- Respects rate limits with delays
- Limits unfollows per session
- Requires confirmation before starting
- Shows progress in console
⚠️ IMPORTANT NOTES:
- Use responsibly and don't abuse
- Instagram may temporarily limit your actions if you go too fast
- Script is designed to work within Instagram's guidelines
- Always review the list before confirming
πŸš€ Ready to start? Type: unfollowNonFollowers()
`);
// Export the function to global scope
window.unfollowNonFollowers = unfollowNonFollowers;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment