Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Instagram Unfollowers: Get a list of people whom you follow but who do not follow you back on Instagram as well as the list of people who follow you but whom you don't follow back!
// Gist by acesmndr@gmail.com Rev 2.1.2 May 15, 2019
// go to your insta profile page (not the home page). It looks something like this: https://instagram.com/YOUR_PROFILE
// Open javascript console "Ctrl + Shift + i" in Windows/Linux and "Cmd + option + i" in Mac.
// Paste the entire code below to the console and hit enter
// You will get the list of people whom you follow but who don't follow you back and viceversa as well as the entire list of followers and following
var following = [],
followers = [],
followersCount = 0,
followingCount = 0,
scrolledFollowersCount = 0,
scrolledFollowingCount = 0,
hashtagCount,
scrollingCount = 0; // temp variable to store the count for following and followers while scrolling
function diff(array) {
return function (current) {
return array.filter(function (element) {
return element.userId === current.userId && element.userName == current.userName;
}).length == 0;
}
}
function openFollowersDialog(){
if (!document.querySelector('a[href*="/followers/"]')) {
console.clear();
console.error('You are most likely in the homepage and not the profile page. It is the page with your photos only.');
return;
}
followersCount = parseInt(document.querySelector('a[href*="/followers/"]').firstElementChild.textContent);
document.querySelector('a[href*="/followers/"]').click() // go to Followers
setTimeout(function(){
console.clear();
console.debug(`Please wait...`);
scrollFollowers();
},1000);
}
function openFollowingDialog() {
followingCount = parseInt(document.querySelector('a[href*="/following/"]').firstElementChild.textContent);
document.querySelector('a[href*="/following/"]').click(); // go to followers
setTimeout(function () {
console.clear();
console.debug(`Please wait...`);
scrollFollowing();
}, 2000);
}
function scrollFollowers(){
var scrollDiv = document.querySelector('div[role="presentation"]').querySelector('li').parentElement;
scrollDiv.lastElementChild.scrollIntoView();
console.clear();
console.debug(`Loaded ${scrollDiv.childElementCount} out of ${followersCount} followers. Please wait...`);
setTimeout(function(){
if (scrollDiv.childElementCount === followersCount || (scrollingCount === scrollDiv.childElementCount && (followersCount - scrollingCount) < hashtagCount)) {
scrolledFollowersCount = scrollDiv.childElementCount;
getFollowers();
console.clear();
console.debug(`Please wait while the following list is loaded...`);
setTimeout(function(){
console.clear();
console.info(`Scroll Followers completed with ${followersCount} people`);
console.debug(`Please wait...`);
scrollingCount = 0;
openFollowingDialog();
}, 3000);
} else {
scrollingCount = scrollDiv.childElementCount; // current count of loaded followers
scrollFollowers();
}
},1000);
}
function scrollFollowing() {
var scrollDiv = document.querySelector('div[role="presentation"]').querySelector('li').parentElement;
scrollDiv.lastElementChild.scrollIntoView();
console.clear();
console.debug(`Loaded ${scrollDiv.childElementCount} out of ${followingCount} following people. Please wait...`);
setTimeout(function () {
if (scrollDiv.childElementCount === followingCount || (scrollingCount === scrollDiv.childElementCount && (followingCount - scrollingCount) < hashtagCount)) {
scrolledFollowingCount = scrollDiv.childElementCount;
getFollowing();
console.info(`Scroll following completed with ${followingCount} people`);
setTimeout(function () {
document.querySelector('[aria-label="Close"]').click();
getResults();
}, 1000);
} else {
scrollingCount = scrollDiv.childElementCount; // current count of loaded following people
scrollFollowing();
}
}, 1000);
}
function getFollowers(){
var followersDiv = document.querySelector('div[role="presentation"]').querySelector('li').parentElement.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].lastElementChild.children[0].children[1];
followers.push({
userID: tempUser.children[0].textContent,
userName: tempUser.children[1].textContent,
});
}
document.querySelector('[aria-label="Close"]').click();
}
function getFollowing(){
var followersDiv = document.querySelector('div[role="presentation"]').querySelector('li').parentElement.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].lastElementChild.children[0].children[1];
following.push({
userID: tempUser.children[0].textContent,
userName: tempUser.children[1].textContent,
});
}
}
function getResults(){
console.clear();
var consoleColors = 'color:#bada55;background:black;font-weight:bold;font-size:20px';
console.info('The results might shock you! Keep calm!');
console.log('Your following list:', following);
console.log('Your followers list:', followers);
var unfollowing = following.filter(diff(followers));
console.log(`%c There are ${unfollowing.length} people who you are following but who don\'t follow you. They are:`, consoleColors);
console.table(unfollowing);
var unfollowers = followers.filter(diff(following));
console.log(`%c There are ${unfollowers.length} people who are following you but who you aren\'t following. They are:`, consoleColors);
console.table(unfollowers);
console.info(`You have loaded ${scrolledFollowersCount} out of ${followersCount} followers and ${scrolledFollowingCount} out of ${followingCount} of the people you follow.`);
console.info('If the above numbers differ by a huge amount then you need to run the script again. Don\'t switch to another page while the script is running');
console.info(`There are hashtags in people you follow. It's based on the assumption that you follow hashtags below 10. If you follow somewhere above 10. then run 'getInstagramStats(20) if you follow 20 hashtags'`);
console.info(`%c For a social cause: acesmndr@gmail.com`, consoleColors);
}
var getInstagramStats = function(htagCount) {
if (/(http\:|https\:)\/\/(www.)instagram.com\//.test(location.href)) {
hashtagCount = htagCount + 1;
openFollowersDialog();
} else {
console.clear();
console.error('You should be in your instagram profile in order to execute the script');
}
}
getInstagramStats(10);
@Schludi

This comment has been minimized.

Copy link

Schludi commented Mar 12, 2018

Hi! I just tried it but get the following error message:
VM48:12 Uncaught TypeError: Cannot read property 'querySelector' of undefined
at goToSubscribers (:12:67)
at :83:1

@Acesmndr

This comment has been minimized.

Copy link
Owner Author

Acesmndr commented Jan 2, 2019

@Schludi Since the last implementation was totally dependent on the classname of the tags present in the instagram site it got outdated when Instagram updated their site. I have updated the script to work irrespective of the tags now.

It's working now but the usernames are redacted as they are from my list.
screen shot 2019-01-02 at 5 19 58 pm

P.S. Sorry for the late reply. I don't remember getting notification for your comment on my gist. It must be due to my habit of doing "Mark all as read".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.