Skip to content

Instantly share code, notes, and snippets.

@dacastro4
Last active March 1, 2025 17:09
Show Gist options
  • Save dacastro4/5c47b624a33ec3389b99cc3c614a1e9a to your computer and use it in GitHub Desktop.
Save dacastro4/5c47b624a33ec3389b99cc3c614a1e9a to your computer and use it in GitHub Desktop.
Instagram mass remove followers
(async function () {
//Config
const UNFOLLOW_LIMIT = 4;
const REMOVE_LIST = [];
const REMOVED_LIST = [];
const CLASS_LIST = 'x1dm5mii x16mil14 xiojian x1yutycm x1lliihq x193iq5w xh8yej3';
const $followers = document.querySelectorAll('.' + CLASS_LIST.replace(/ /g, '.'));
const delay = (ms) => new Promise(_ => setTimeout(_, ms));
const findButtonRemoveButton = (parent, selector = '*') => [...parent.querySelectorAll(selector).entries()].map(([pos, btn]) => btn).filter(btn => btn.textContent.trim() === 'Remove')[0];
const randomBetween30And60s = () => Math.floor(Math.random() * 30) + 30;
const findNodeWithText = (rootNode, searchText) => {
if (!rootNode) {
return null;
}
if (rootNode.nodeType === Node.TEXT_NODE && rootNode.nodeValue?.includes(searchText)) {
return rootNode;
}
for (let i = 0; i < rootNode.childNodes.length; i++) {
const foundNode = findNodeWithText(rootNode.childNodes[i], searchText);
if (foundNode) {
return foundNode;
}
}
return null;
}
const findFollowerNode = (username) => {
for (let i = 0; i < $followers.length; i++) {
const $follower = $followers[i];
const $username = findNodeWithText($follower, username);
if ($username) {
console.log("Found", username)
return $follower;
}
}
}
const clickConfirmModal = () => {
const dialogs = document.querySelectorAll('div[role=dialog]');
if (dialogs.length === 0) {
console.warn('Could not find modal');
return;
}
const lastDialog = dialogs[dialogs.length - 1];
const $removeButton = findButtonRemoveButton(lastDialog, 'button');
if ($removeButton) {
$removeButton.click();
}
}
console.log("Start")
if (!$followers.length) {
console.log("No followers found")
return
}
console.log("Found followers")
for (let i = 0; i < REMOVE_LIST.length && i < UNFOLLOW_LIMIT; i++) {
console.log("Searching", REMOVE_LIST[i]);
let $followerNode = findFollowerNode(REMOVE_LIST[i], $followers);
if ($followerNode) {
const $confirm = findButtonRemoveButton($followerNode);
if ($confirm) {
$confirm.click();
REMOVED_LIST.push(REMOVE_LIST[i]);
console.log(`Removed ${REMOVE_LIST[i]}`);
await delay(1000); // Wait for confirmation modal
clickConfirmModal();
await delay(randomBetween30And60s());
}
} else {
console.log(`Could not find ${REMOVE_LIST[i]}`);
}
}
console.log("The end");
console.log('We removed these followers:', REMOVED_LIST);
})();

I had an issue with an account that had many many bots followers affecting their engagement so I created this script to remove them. Instagram has a hard guideline to remove followers. I recommend not deleting more than 4 per hours and 40 per day. Use it wisely

Go to your profile on instagram.com (sign in if not already) Click on XXX followers for the popup with the users that follow you Open Chrome Devtools and paste the content of script.js and hit enter

if the script saved you a lot of time (and/or money) you can buy me a coffee

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