Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@berstend
Last active December 23, 2023 14:37
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save berstend/752e7b54fd0bbd8b672882459d149b60 to your computer and use it in GitHub Desktop.
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")
})()
@bricsx
Copy link

bricsx commented Jan 25, 2022

ty

@a-mangareader
Copy link

ayo my dude how do i add exceptions to the list :<

@Tpcoo
Copy link

Tpcoo commented May 17, 2022

someone help TP#1000 add cord

@mamorutakamura
Copy link

it aint working

@FaisalAhmed123
Copy link

Just get this but nothing happens
image

@macedonga
Copy link

This updated code will work (it's working for me):

(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.innerText === 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")
})()

@vatistasdimitris1
Copy link

vatistasdimitris1 commented Dec 23, 2023

Here I am ed developer and I have Upgraded the code for you here:

(async function () {
const UNFOLLOW_LIMIT = 800;
const UNFOLLOW_INTERVAL = 0; // Unfollow as quickly as possible
const BREAK_DURATION = 5 * 60 * 1000; // 5 minutes break
const TOTAL_DURATION = 10 * 60 * 1000; // 10 minutes duration

let stopScript = false;

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const findButton = (txt) =>
[...document.querySelectorAll("button").entries()]
.map(([pos, btn]) => btn)
.filter((btn) => btn.innerText === txt)[0];

console.log("Start");

let startTime = new Date().getTime();

// Interval to check for user input to stop the script
const stopInterval = setInterval(() => {
if (stopScript) {
console.log("Script stopped by user.");
clearInterval(stopInterval);
}
}, 1000);

while (new Date().getTime() - startTime < TOTAL_DURATION && !stopScript) {
for (let i = 0; i < UNFOLLOW_LIMIT && !stopScript; i++) {
const $next = findButton("Following");
if (!$next) {
continue;
}
$next.scrollIntoViewIfNeeded();
$next.click();
await delay(100);
const $confirm = findButton("Unfollow");
if ($confirm) {
await $confirm.click(); // Wait for the unfollow to complete
}

  await delay(UNFOLLOW_INTERVAL);
  console.log(`Unfollowed #${i}`);
}

console.log(`Taking a break for ${BREAK_DURATION / 1000} seconds...`);
await delay(BREAK_DURATION);

if (!stopScript) {
  startTime = new Date().getTime(); // Reset start time for the next cycle
}

}

console.log("T

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