Skip to content

Instantly share code, notes, and snippets.

@berstend
Last active December 5, 2025 10:51
Show Gist options
  • Select an option

  • Save berstend/752e7b54fd0bbd8b672882459d149b60 to your computer and use it in GitHub Desktop.

Select an option

Save berstend/752e7b54fd0bbd8b672882459d149b60 to your computer and use it in GitHub Desktop.
Mass unfollow users on Instagram (no app needed)
  • Go to your profile on instagram.com (sign in if not already)
  • Click on XXX following for the popup with the users you're following to appear
  • Open Chrome Devtools and Paste the following into the Console and hit return:
(async function(){
  const UNFOLLOW_LIMIT = 800
  const delay = (ms) => new Promise(_ => setTimeout(_, ms))
  const findButton = (txt) => [...document.querySelectorAll("button").entries()].map(([pos, btn]) => btn).filter(btn => btn.innerHTML === txt)[0]

  console.log("Start")
  for (let i = 0; i < UNFOLLOW_LIMIT; i++) {
    const $next = findButton("Following")          
    if (!$next) { continue }
    $next.scrollIntoViewIfNeeded()  
    $next.click()
    await delay(100)
    $confirm = findButton("Unfollow")    
    if ($confirm) {
      $confirm.click()
    }

    await delay(20 * 1000) // Wait 20s, 200 unfollows per hour limit
    console.log(`Unfollowed #${i}`)
  }

  console.log("The end")
})()
@kader68github
Copy link

This script made with ai and tested by me works very fine!!

(async function() {
var UNFOLLOW_LIMIT = 800;
var DELAY_BETWEEN_ACTIONS = 2000;
var DELAY_AFTER_CLICK = 300;
var MAX_RETRIES = 3;
var isRunning = true;

function delay(ms) {
return new Promise(function(resolve) {
setTimeout(resolve, ms);
});
}

function findButton(txt, root) {
if (!root) root = document;
var buttons = root.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
var btnText = buttons[i].textContent.trim().toLowerCase();
if (btnText.indexOf(txt.toLowerCase()) !== -1) {
return buttons[i];
}
}
return null;
}

function randomDelay(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Creer le bouton STOP
var stopButton = document.createElement("div");
stopButton.id = "unfollowStopBtn";
stopButton.innerHTML = "⏹ ARRETER
Unfollows: 0";
stopButton.style.cssText = "position:fixed;top:20px;right:20px;z-index:999999;background:#ff4444;color:white;padding:15px 25px;border-radius:10px;cursor:pointer;font-family:Arial;font-size:16px;font-weight:bold;box-shadow:0 4px 15px rgba(0,0,0,0.3);text-align:center;transition:all 0.3s;";

stopButton.onmouseover = function() {
this.style.background = "#cc0000";
this.style.transform = "scale(1.05)";
};

stopButton.onmouseout = function() {
this.style.background = "#ff4444";
this.style.transform = "scale(1)";
};

stopButton.onclick = function() {
isRunning = false;
this.innerHTML = "✓ ARRETE";
this.style.background = "#666";
this.style.cursor = "default";
this.onclick = null;
console.log("Script arrete par l'utilisateur");
};

document.body.appendChild(stopButton);

console.log("Demarrage du script Instagram Unfollow");
console.log("Limite: " + UNFOLLOW_LIMIT + " comptes");
console.log("Delai entre actions: " + DELAY_BETWEEN_ACTIONS + "ms");
console.log("--------------------------------------------------");
console.log("CONSEIL: Cliquez sur le bouton rouge en haut a droite pour arreter");

var successCount = 0;
var failCount = 0;

for (var i = 0; i < UNFOLLOW_LIMIT; i++) {
if (!isRunning) {
console.log("Script arrete manuellement");
break;
}

try {
  var followingBtn = findButton("Following");
  if (!followingBtn) {
    followingBtn = findButton("Abonne");
  }
  
  if (!followingBtn) {
    console.log("Plus de boutons 'Following' trouves");
    break;
  }

  followingBtn.scrollIntoView({ behavior: "smooth", block: "center" });
  await delay(300);
  followingBtn.click();
  await delay(DELAY_AFTER_CLICK);

  var confirmClicked = false;
  
  for (var attempt = 0; attempt < MAX_RETRIES; attempt++) {
    if (!isRunning) break;
    
    var dialogs = document.querySelectorAll('[role="dialog"]');
    
    for (var d = 0; d < dialogs.length; d++) {
      var confirmBtn = findButton("Unfollow", dialogs[d]);
      if (!confirmBtn) {
        confirmBtn = findButton("Ne plus suivre", dialogs[d]);
      }
      
      if (confirmBtn) {
        confirmBtn.click();
        confirmClicked = true;
        successCount++;
        
        // Mettre a jour le compteur sur le bouton
        var countElement = document.getElementById("unfollowCount");
        if (countElement) {
          countElement.textContent = successCount;
        }
        
        console.log("Unfollow #" + successCount + " (tentative " + (i + 1) + "/" + UNFOLLOW_LIMIT + ")");
        
        if (document.activeElement) {
          document.activeElement.blur();
        }
        
        await delay(DELAY_AFTER_CLICK);
        break;
      }
    }
    
    if (confirmClicked) break;
    await delay(200);
  }

  if (!confirmClicked) {
    failCount++;
    console.log("Echec #" + failCount + " - Bouton de confirmation non trouve");
  }

  var waitTime = randomDelay(DELAY_BETWEEN_ACTIONS, DELAY_BETWEEN_ACTIONS + 1000);
  await delay(waitTime);

  if (successCount > 0 && successCount % 50 === 0) {
    console.log("Progression: " + successCount + " unfollows reussis");
  }

} catch (error) {
  console.error("Erreur a l'iteration " + (i + 1) + ":", error.message);
  failCount++;
  await delay(3000);
}

}

console.log("--------------------------------------------------");
console.log("Script termine !");
console.log("Succes: " + successCount);
console.log("Echecs: " + failCount);
console.log("Total traite: " + (successCount + failCount));
console.log("--------------------------------------------------");

// Retirer le bouton apres la fin
setTimeout(function() {
var btn = document.getElementById("unfollowStopBtn");
if (btn) {
btn.style.opacity = "0";
setTimeout(function() {
if (btn.parentNode) {
btn.parentNode.removeChild(btn);
}
}, 500);
}
}, 3000);

})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment