Skip to content

Instantly share code, notes, and snippets.

@clins1994
Last active December 19, 2021 18:04
Show Gist options
  • Save clins1994/84a7f7ba0cbb813757b8cbfa7b4e1259 to your computer and use it in GitHub Desktop.
Save clins1994/84a7f7ba0cbb813757b8cbfa7b4e1259 to your computer and use it in GitHub Desktop.
Unfollow Everyone on Instagram
// HOW TO RUN IT ON GOOGLE CHROME
// 1. OPEN INSTAGRAM
// 2. OPEN LIST OF FOLLOWERS
// 3. OPEN DEVELOPER TOOLS
// 4. COPY EVERYTHING HERE CTRL + A
// 5. PASTE EVERYTHING IN DEVELOPER TOOLS CONSOLE
// 6. CLICK ENTER
// THERE YOU WILL SOON HAVE NO FRIENDS
const FOLLOWING_BUTTON_TEXT = 'フォロー中' // CHANGE THIS TO YOUR LANGUAGE
const UNFOLLOW_BUTTON_TEXT = 'フォローをやめる' // THIS TOO
const MAX_ATTEMPTS_PER_UNFOLLOW = 3 // BUMP THIS IF YOU HAVE WOODEN PC
const unfollowSomebody = () => {
const followingButton = document
.evaluate(`//button[text()="${FOLLOWING_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
.singleNodeValue
if (followingButton) {
console.log('Found following button. Clicking ...')
followingButton.click()
console.log('Clicked following button.')
let unfollowButton = document.evaluate(`//button[text()="${UNFOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
let attempts = 1
while (attempts < MAX_ATTEMPTS_PER_UNFOLLOW && !unfollowButton) {
console.log(`Attempted to find unfollowButton but could not. Retry #${attempts++}`)
unfollowButton = document.evaluate(`//button[text()="${UNFOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
}
if (attempts < MAX_ATTEMPTS_PER_UNFOLLOW) {
console.log('Found unfollow button. Scrolling and clicking ...')
unfollowButton.scrollIntoView(true)
unfollowButton.click()
} else {
console.log(`Retried ${MAX_ATTEMPTS_PER_UNFOLLOW} times and didn't succeed`)
}
return false
}
return true
}
const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms))
const randomTimeout = () => (Math.floor((Math.random() * 10) + 1) * 1000) + 30000
const unfollowEveryone = async () => {
let shouldStop = false
while (!shouldStop) {
shouldStop = unfollowSomebody()
const unfollowTimeout = randomTimeout()
console.log(`Waiting ${unfollowTimeout} seconds. Should stop: ${shouldStop}.`)
await timeout(unfollowTimeout)
}
console.log('You follow no one.')
}
unfollowEveryone()
@kpr9991
Copy link

kpr9991 commented Jun 9, 2020

Screenshot (183)
Following number didnot change !

@mt-caio
Copy link

mt-caio commented Jun 13, 2020

@kpr9991 you need to open following list first. Also don’t forget to change texts from Japanese to English.

@kpr9991
Copy link

kpr9991 commented Jun 13, 2020

Screenshot (184)
How much time will it take??

@clins1994
Copy link
Author

clins1994 commented Jun 14, 2020 via email

@terran183
Copy link

Thank you for the code, it`s working perfect, just a small question. Is there a way to select the profiles?

@chaodonghu
Copy link

chaodonghu commented Aug 19, 2020

@kpr9991 It takes long time due to Instagram API limits. Just let it run overnight.

Thank you so much for this, I tweaked it a little to do the reverse as well to "Follow"

You could always change the randomTimeout however like you said I believe Instagram will detect that you're unfollowing too fast and might ban your account. I believe the limit is ~ 100 accounts per hour.

@mcflerry
Copy link

mcflerry commented Aug 22, 2020

great...

How to loop this script only n times? After that loops it should stop.

Thanks for helping.

@uamzeki
Copy link

uamzeki commented Aug 25, 2020

I'm Lost a bit, I should change the Japanese text to "Follow" and "Unfollow" respectively?

@bcoop99
Copy link

bcoop99 commented Aug 29, 2020

@kpr9991 It takes long time due to Instagram API limits. Just let it run overnight.

Thank you so much for this, I tweaked it a little to do the reverse as well to "Follow"

You could always change the randomTimeout however like you said I believe Instagram will detect that you're unfollowing too fast and might ban your account. I believe the limit is ~ 100 accounts per hour.

@chaodonghu Would you be willing to provide the "Follow" script you made? also, were you able to limit the number it would follow? You get action blocked if you follow more than 120 a day, I think.

@chaodonghu
Copy link

chaodonghu commented Aug 30, 2020

@kpr9991 It takes long time due to Instagram API limits. Just let it run overnight.

Thank you so much for this, I tweaked it a little to do the reverse as well to "Follow"
You could always change the randomTimeout however like you said I believe Instagram will detect that you're unfollowing too fast and might ban your account. I believe the limit is ~ 100 accounts per hour.

@chaodonghu Would you be willing to provide the "Follow" script you made? also, were you able to limit the number it would follow? You get action blocked if you follow more than 120 a day, I think.

Here's my follow gist, https://gist.github.com/chaodonghu/c25c7ee3e3eb85c0a0de051892e596a4 which is basically an adopted version of this gist.

You can limit the number you follow by putting a counter if you'd like and just loop over the function x times (eg. hit 120 a day). However the follow/action limits seem to be capped per hour not per day. I would just change the timeout function accordingly

@dfc201692
Copy link

Amigo Buenas noches, este script sirve para dejar de seguir ? necesito borrarlos a todos. Gracias

@clins1994
Copy link
Author

Amigo Buenas noches, este script sirve para dejar de seguir ? necesito borrarlos a todos. Gracias

@dfc201692 oi amigo. exactamente 😄

@dfc201692
Copy link

Pero en que navegador funciona? en mozilla no me deja en chrome me genera un error y no puedo avanzar. creo que instagram tiene muchas restricciones y en oacaciones bloquea la cuenta por una semana. necesito de su ayuda.

@mikikuke
Copy link

i ran the code but i get errors

Uncaught SyntaxError: Identifier 'FOLLOWING_BUTTON_TEXT' has already been declared
sdk.js?hash=65a9723ac93bb00926c15e01b6b1ce7c&ua=modern_es6:52 You are overriding current access token, that means some other app is expecting different access token and you will probably break things. Please consider passing access_token directly to API parameters instead of overriding the global settings.

@StefiBondarciuc
Copy link

StefiBondarciuc commented May 4, 2021

Thanks for sharing the code. I actually like to experiment with this type of stuff just for fun, mainly to see if I can write the code all by myself without any bugs. I am trying to get a summer internship in programming, so lately I’ve been working extra hours to improve my skills. I decided to quit all social media, including Instagram. I used this website https://backlightblog.com/edit-hide-delete-instagram-comments to get instructions on how to deactivate the profile, because I understood that you can’t permanently delete it, just deactivate. Anyways, I’m happy with my decision, and now I don’t waste my time on unnecessary things.

@jagdishlove
Copy link

jagdishlove commented Dec 19, 2021

I found a better solution for using this for a profile that is not your friend or has not talked to you, I hope this Script works from starting following, what if we reverse that order from inspecting and then try to run this script, not used but will try and update if any possibilities.

function reverseChildren(element) {
    for (var i = 1; i < element.childNodes.length; i++){
        element.insertBefore(element.childNodes[i], element.firstChild);
    }
}

use this code and reverse your whole following list, then try this script, hope it will work and you will unfollow the right person.

For more lame explanation please visit https://gist.github.com/jagdishlove/2393f32601054600be06fa4d20df5cb8

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