-
-
Save Acesmndr/eb9fdc42b8fed0416ee658af692adb69 to your computer and use it in GitHub Desktop.
// 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: [email protected]`, 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); |
All the
document.querySelector('[aria-label="Close"]').click();
should be changed to
document.querySelector('[aria-label="Close"]').parentElement.parentElement.click();
Not working, just tested it.
updated:
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.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.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.debug(`Please wait...`);
scrollFollowing();
}, 2000);
}
function scrollFollowers(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
scrollDiv.lastElementChild.scrollIntoView();
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.debug(`Please wait while the following list is loaded...`);
setTimeout(function(){
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="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
scrollDiv.lastElementChild.scrollIntoView();
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"]').parentElement.parentElement.click();
getResults();
}, 1000);
} else {
scrollingCount = scrollDiv.childElementCount; // current count of loaded following people
scrollFollowing();
}
}, 1000);
}
function getFollowers(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
var followersDiv = scrollDiv.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].children[1];
followers.push({
userID: tempUser.children[0]?.textContent,
userName: tempUser.children[1]?.textContent,
url: `https://www.instagram.com/${tempUser.children[0]?.textContent}`
});
}
document.querySelector('[aria-label="Close"]').parentElement.parentElement.click();
}
function getFollowing(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
var followersDiv = scrollDiv.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].children[1];
following.push({
userID: tempUser.children[0]?.textContent,
userName: tempUser.children[1]?.textContent,
url: `https://www.instagram.com/${tempUser.children[0]?.textContent}`
});
}
}
function getResults() {
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'`);
}
var getInstagramStats = function(htagCount) {
if (/(http\:|https\:)\/\/(www.)instagram.com\//.test(location.href)) {
hashtagCount = htagCount + 1;
openFollowersDialog();
} else {
console.error('You should be in your instagram profile in order to execute the script');
}
}
getInstagramStats(10);
getting this error "Cannot read properties of null (reading 'scrollIntoView')"
Updated (until IG breaks it again)
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.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.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.debug(`Please wait...`);
scrollFollowing();
}, 2000);
}
function scrollFollowers(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
scrollDiv.lastElementChild.scrollIntoView();
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.debug(`Please wait while the following list is loaded...`);
setTimeout(function(){
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="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
scrollDiv.lastElementChild.scrollIntoView();
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"]').parentElement.parentElement.click();
getResults();
}, 1000);
} else {
scrollingCount = scrollDiv.childElementCount; // current count of loaded following people
scrollFollowing();
}
}, 1000);
}
function getFollowers(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
var followersDiv = scrollDiv.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].children[0].children[0].children[0].children[1].children[0].children[0];
followers.push({
userID: tempUser.children[0]?.textContent,
userName: tempUser.children[1]?.textContent,
url: `https://www.instagram.com/${tempUser.children[0]?.textContent}`
});
}
document.querySelector('[aria-label="Close"]').parentElement.parentElement.click();
}
function getFollowing(){
var scrollDiv = document.querySelector('div[role="dialog"] div[role="dialog"] > div > div > div:last-child > div:first-child > div');
var followersDiv = scrollDiv.children;
for (var i = 0;i<followersDiv.length;i++){
var tempUser = followersDiv[i].children[0].children[0].children[0].children[1].children[0].children[0];
following.push({
userID: tempUser.children[0]?.textContent,
userName: tempUser.children[1]?.textContent,
url: `https://www.instagram.com/${tempUser.children[0]?.textContent}`
});
}
}
function getResults() {
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'`);
}
var getInstagramStats = function(htagCount) {
if (/(http\:|https\:)\/\/(www.)instagram.com\//.test(location.href)) {
hashtagCount = htagCount + 1;
openFollowersDialog();
} else {
console.error('You should be in your instagram profile in order to execute the script');
}
}
getInstagramStats(10);
hey how should i use this
How to use it (27-04-2023, still worked):
- Login to your instagram account (via web), go to
Profile
tab - Click the
Followers
text, then open Console tab of your any web browser (google it if you do not understand this dev-tools) - Copy the code to the Console textarea and hit enter; Or run the .js file by download the javascript code, save the file (.js ext.) and open with your web browser that open the instagram
Profile
tab menu - Wait for the result, let the code's running until finish.
- Run one of the functions provided on the .js code, for example: type
getResults()
orgetInstagramStats(10)
in your Console textarea, then hit enter to get the result - Good luck! The latest code you would run on is the latest, the most bottom one in this comment section (look at the comment timestamp)
great work, works like charm!
one tip: you may add some random wait time in between scrolls, just to make it a lot more like human interaction.
Line 30 and 40 breaks if you have more than 1k followers
https://gist.github.com/Acesmndr/eb9fdc42b8fed0416ee658af692adb69#file-instagramunfollowers-js-L30
https://gist.github.com/Acesmndr/eb9fdc42b8fed0416ee658af692adb69#file-instagramunfollowers-js-L40
Ex: for line 40
it should be parseInt(document.querySelector('a[href*="/followers/"]').firstElementChild.textContent.replace(',', ''))
Add .replace(',', '')
in line 30 the same way.
@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.

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".