Skip to content

Instantly share code, notes, and snippets.

@dante4rt
Created March 4, 2026 16:07
Show Gist options
  • Select an option

  • Save dante4rt/b6f61a50b054f4ca889da3e8739f1549 to your computer and use it in GitHub Desktop.

Select an option

Save dante4rt/b6f61a50b054f4ca889da3e8739f1549 to your computer and use it in GitHub Desktop.
Auto-unfollow all Instagram followings via browser console: clicks Following buttons, confirms unfollows, and auto-scrolls to load more.
/**
* Instagram Auto-Unfollow Script
* ─────────────────────────────────────────────────────────────────
* 1. Go to https://www.instagram.com/{username}/following/
* 2. Open the Following modal
* 3. Paste this script into DevTools > Console and press Enter
* ─────────────────────────────────────────────────────────────────
*/
(async () => {
const DELAY_UNFOLLOW = 1500; // ms between each unfollow action
const DELAY_SCROLL = 2000; // ms to wait after scroll (for new items to load)
const MAX_NO_SCROLL = 3; // stop after this many consecutive failed scroll attempts
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
function findScrollContainer() {
// The list lives inside a div[style*="overflow"] whose PARENT has a fixed CSS height.
// We target the parent because the inner div has height:auto and cannot scroll itself.
const overflowDiv = document.querySelector('[role="dialog"] div[style*="overflow"]');
if (overflowDiv) return overflowDiv.parentElement;
// Fallback: walk up from a button to the first element that can scroll
let el = document.querySelector('button._aswp')?.parentElement;
while (el && el !== document.body) {
if (el.scrollHeight > el.clientHeight) return el;
el = el.parentElement;
}
return null;
}
function getFollowingButtons() {
return [...document.querySelectorAll('button._aswp')]
.filter((btn) => btn.innerText.trim() === 'Following');
}
async function confirmUnfollow() {
await sleep(600);
const confirmBtn = [...document.querySelectorAll('[role="dialog"] button')]
.find((btn) => btn.innerText.trim() === 'Unfollow');
confirmBtn?.click();
await sleep(400);
}
async function unfollowVisible() {
const buttons = getFollowingButtons();
console.log(`▶ Found ${buttons.length} Following button(s)`);
for (const btn of buttons) {
btn.click();
await confirmUnfollow();
await sleep(DELAY_UNFOLLOW);
}
return buttons.length;
}
// ─── Main ────────────────────────────────────────────────────────────────
const container = findScrollContainer();
if (!container) {
return console.error('❌ Scroll container not found. Make sure the Following modal is open.');
}
console.log('✅ Scroll container found:', container);
let total = 0;
let noScrollStreak = 0;
while (noScrollStreak < MAX_NO_SCROLL) {
total += await unfollowVisible();
const before = container.scrollTop;
container.scrollTop += container.clientHeight;
await sleep(DELAY_SCROLL);
const after = container.scrollTop;
console.log(`⬇ Scrolled ${before}${after} | Total unfollowed: ${total}`);
noScrollStreak = after === before ? noScrollStreak + 1 : 0;
}
console.log(`🎉 Done! Total unfollowed: ${total}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment