-
-
Save lifenautjoe/01828b35132adc096500c2ea9b8c313d to your computer and use it in GitHub Desktop.
/** | |
* Instagram web unfollow script | |
* | |
* WHAT IS IT? | |
* A script to unfollow people in the instagram website | |
* | |
* WHY? | |
* I needed to clean my account so I quickly did this | |
* | |
* HOW TO USE: | |
* Go to your instagram profile while logged in and run the following code in your console | |
* | |
* WHAT DOES IT DO EXACTLY? | |
* It opens your followers list and goes one by one unfollowing with a random interval of 1 to 10 | |
* seconds in between | |
* | |
* CAN I GET BANNED? | |
* Yes, although you will first be notified several times about strange activity | |
* Simply put, use it at your own risk and not for long. | |
* | |
* Created on 15/03/17. | |
* @author Joel Hernandez <involvmnt@gmail.com> | |
*/ | |
openFollowersWindow().then(function () { | |
populateUnfollowsPool(); | |
digestUnfollowsPool(); | |
}); | |
function openFollowersWindow() { | |
var onFollowersWindowWasOpenedListeners = []; | |
var openWindowTimeout = 3000; | |
var followersElement = getFollowersElement(); | |
followersElement.click(); | |
function digestOnFollowersWindowWasOpenedListeners() { | |
onFollowersWindowWasOpenedListeners.forEach(function (onFollowersWindowWasOpenedListener) { | |
onFollowersWindowWasOpenedListener(); | |
}); | |
} | |
var wasOpened; | |
setTimeout(function () { | |
// TODO Verify that the window was indeed opened | |
wasOpened = true; | |
digestOnFollowersWindowWasOpenedListeners(); | |
}, openWindowTimeout); | |
return { | |
then: function (onFollowersWindowWasOpened) { | |
if (wasOpened) { | |
onFollowersWindowWasOpened(); | |
} else { | |
onFollowersWindowWasOpenedListeners.push(onFollowersWindowWasOpened); | |
} | |
} | |
}; | |
} | |
function getFollowersElement() { | |
return getFollowersElementWithUsername(getUsername()); | |
} | |
function getUsername() { | |
var pageTitleElement = document.getElementsByTagName('h1')[0]; | |
if (!pageTitleElement) throw new Error('No title to get username from'); | |
return pageTitleElement.innerHTML; | |
} | |
function getFollowersElementWithUsername(username) { | |
var followersElement = document.querySelectorAll('a[href="/' + username + '/following/"]')[0]; | |
if (!followersElement) throw new Error('No followers element was found'); | |
return followersElement; | |
} | |
var unfollowsPool; | |
function populateUnfollowsPool() { | |
var buttons = document.getElementsByTagName('button'); | |
unfollowsPool = []; | |
for (var i = 0; i < buttons.length; i++) { | |
var button = buttons[i]; | |
if (button.innerHTML.includes('Following')) { | |
var randomTimeoutForUnfollow = Math.floor((Math.random() * 10) + 1) * 1000; | |
console.log('Following button!'); | |
var unfollow = { | |
buttonElement: button, | |
timeout: randomTimeoutForUnfollow | |
}; | |
unfollowsPool.push(unfollow); | |
} | |
} | |
} | |
function digestUnfollowsPool() { | |
if (unfollowsPool.length === 0) { | |
console.log('Unfollow pool empty, repopulating'); | |
populateUnfollowsPool(); | |
} | |
var unfollow = unfollowsPool.shift(); | |
var unfollowTimeout = unfollow.timeout; | |
console.log('Clicking unfollow button in ', unfollowTimeout); | |
setTimeout(function () { | |
var unfollowButtonElement = unfollow.buttonElement; | |
unfollowButtonElement.scrollIntoView(true); | |
console.log('Clicking unfollow button'); | |
unfollowButtonElement.click(); | |
console.log('Clicked. Continuing digesting unfollow pool'); | |
digestUnfollowsPool(); | |
}, unfollowTimeout); | |
} |
And thanks to @lifenautjoe who wrote and shared!
how exactly to use this script? Inside google chrome?
legend! it works!
I am getting this error.
VM15346:79 Uncaught TypeError: Cannot read property 'timeout' of undefined
at digestUnfollowsPool (<anonymous>:79:36)
at <anonymous>:3:5
at <anonymous>:15:13
at Array.forEach (<anonymous>)
at digestOnFollowersWindowWasOpenedListeners (<anonymous>:14:45)
at <anonymous>:23:9
Someone could help me ?
I had to fix several issues before I could get it running. However, although I chose long delays between the calls, Instagram took away the "Unfollow" button for me after about one and a half days. There were no warnings before and I am not banned, but stuck with a lot of following I did not initiate.
Any chance we can get one that does the same thing but follows instead of unfollows?
Thanks in advance guys!
Just confirming that @pejman-saberin 's revision for the unfollow confirmation button works great, but combined with @bennyxavier007 's timings I only got thru 15 unfollows before getting 403'd. Will try again tomorrow!
Plugged thru the remaining couple hundred with the original timings just fine, thanks!
I am getting this error.
VM15346:79 Uncaught TypeError: Cannot read property 'timeout' of undefined at digestUnfollowsPool (<anonymous>:79:36) at <anonymous>:3:5 at <anonymous>:15:13 at Array.forEach (<anonymous>) at digestOnFollowersWindowWasOpenedListeners (<anonymous>:14:45) at <anonymous>:23:9
It's a shame that nobody helped you with that. You use instagram in a different language. E.g. if you use Instagram in German, you would have to search for the word "Following" and replace it with "Abonniert" (using @pejman-saberin 's Code as a reference). It will work then.
Agradezco el amigo de ayuda, pero lo estoy usando en inglés. Contraté a alguien en fiverr para dejar de seguir toda mi lista. ¡Gracias de todos modos! El 14 de febrero de 2020 a las 18:12, Sebastian notifications@github.com escribió: Recibo este error. VM15346: 79 Error de tipo no capturado: no se puede leer la propiedad 'tiempo de espera' de undefined en digestUnfollowsPool (<anónimo>: 79: 36) en <anónimo>: 3: 5 en <anónimo>: 15: 13 en Array.forEach (<anónimo>) en digestOnFollowersWindowWasOpenedListeners (<anónimo>: 14: 45) en <anónimo>: 23: 9 Es una pena que nadie te haya ayudado con eso. Usas instagram en un idioma diferente. Por ejemplo, si usa Instagram en alemán, tendría que buscar la palabra "Siguiente" y reemplazarla con "Abonniert" (usando @ pejman-saberin's Code como referencia). Funcionará entonces. —Estás recibiendo esto porque has comentado. Responde directamente a este correo electrónico, míralo en GitHub o cancela la suscripción.
can you please send me your fiverr script. im using it in english too and i have the same error...
Buena tarde amigo, este Script todavia sirve ? necesito borrar un poco de de seguidos, aproximadamente 7000 y quiero borrarlos a todos, este es mi perfil, https://www.instagram.com/dafecruz2/ Necesito de su colaboracion
How do i use this
here is the updated version
not working
not a js programmer, so don't understand all parts of the script. tried to make code changes on my local copy to see if i could populate the list with only 100 followers, but i obviously don't know js, so things didn't work. wondering if the original dev (@adminy) would be interested in making this change in the script, so that in stead of populating the list with "all" followers, populate the list with only 100 odd followers. that would also be good to ensure that we don't get banned by instag.
this is urgent, because (1) i have maintained a private account so far, (2) i am following over 1000 accounts, most of which i do not wish to share with others - friends and family (3) a new, "very close friend" wants to follow me or see the list of people i am following. #3 mandates that i clean up my list asap. your help is appreciated.
try this
const unfollow = setInterval(()=>{
const allElements = document.getElementsByClassName("_aacl _aaco _aacw _adda _aad6 _aade");
for (const el of allElements) {
el.click();
setTimeout(() => console.log('espera'), 1000);
setTimeout(() => {
const xpath = "//a[text()='Dejar de seguir']";
const matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
matchingElement.click();
},2000);
setTimeout(() => console.log('espera'), 1000);
}
}, 2000);
clearInterval(unfollow);
Updated version: https://gist.github.com/mikeknapp/788cb26da096161ef3fff1015d947405
How to use it like how to open it.
im new in that and im with c#
@churu88
For the second confirm add this:
//Second confirm
var el=document.getElementsByClassName("aOOlW -Cab_ ");
for (var i=0;i<el.length; i++) {
el[i].click();
}
The whole code then will be then the following:
/**
*/
openFollowersWindow().then(function () {
populateUnfollowsPool();
digestUnfollowsPool();
});
function openFollowersWindow() {
var onFollowersWindowWasOpenedListeners = [];
var openWindowTimeout = 3000;
}
function getFollowersElement() {
return getFollowersElementWithUsername(getUsername());
}
function getUsername() {
var pageTitleElement = document.getElementsByTagName('h1')[0];
if (!pageTitleElement) throw new Error('No title to get username from');
return pageTitleElement.innerHTML;
}
function getFollowersElementWithUsername(username) {
var followersElement = document.querySelectorAll('a[href="/' + username + '/following/"]')[0];
if (!followersElement) throw new Error('No followers element was found');
return followersElement;
}
var unfollowsPool;
function populateUnfollowsPool() {
var buttons = document.getElementsByTagName('button');
unfollowsPool = [];
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
if (button.innerHTML.includes('Following')) {
var randomTimeoutForUnfollow = Math.floor((Math.random() * 60) + 58) * 1000;
console.log('Following button!');
}
function digestUnfollowsPool() {
if (unfollowsPool.length === 0) {
console.log('Unfollow pool empty, repopulating');
populateUnfollowsPool();
}
var unfollow = unfollowsPool.shift();
var unfollowTimeout = unfollow.timeout;
console.log('Clicking unfollow button in ', unfollowTimeout);
setTimeout(function () {
var unfollowButtonElement = unfollow.buttonElement;
unfollowButtonElement.scrollIntoView(true);
console.log('Clicking unfollow button');
unfollowButtonElement.click();
//Second confirm
var el=document.getElementsByClassName("aOOlW -Cab_ ");
for (var i=0;i<el.length; i++) {
el[i].click();
}
console.log('Clicked. Continuing digesting unfollow pool');
digestUnfollowsPool();
}, unfollowTimeout);
}