[GH-ISSUE #12] Exclude accounts from automatic unfollow #203

Closed
opened 2026-03-07 20:15:11 +03:00 by kerem · 4 comments
Owner

Originally created by @shiner66 on GitHub (Jun 9, 2022).
Original GitHub issue: https://github.com/davidarroyo1234/InstagramUnfollowers/issues/12

Would it be possibile to exclude some accounts I don't want to be auto-unfollowed? E.g. pages and such

Originally created by @shiner66 on GitHub (Jun 9, 2022). Original GitHub issue: https://github.com/davidarroyo1234/InstagramUnfollowers/issues/12 Would it be possibile to exclude some accounts I don't want to be auto-unfollowed? E.g. pages and such
kerem closed this issue 2026-03-07 20:15:11 +03:00
Author
Owner

@davidarroyo1234 commented on GitHub (Jun 21, 2022):

Would it be possibile to exclude some accounts I don't want to be auto-unfollowed? E.g. pages and such

I could customize the script a little bit to not unfollow certain users etc.. or to not unfollow account with higher follower count than X. If you are ok with that I will post here a modified script.

<!-- gh-comment-id:1162286806 --> @davidarroyo1234 commented on GitHub (Jun 21, 2022): > Would it be possibile to exclude some accounts I don't want to be auto-unfollowed? E.g. pages and such I could customize the script a little bit to not unfollow certain users etc.. or to not unfollow account with higher follower count than X. If you are ok with that I will post here a modified script.
Author
Owner

@shiner66 commented on GitHub (Jun 21, 2022):

Yeah, both solutions would actually be appreciated for multiple use cases.

Thank you!

<!-- gh-comment-id:1162297549 --> @shiner66 commented on GitHub (Jun 21, 2022): Yeah, both solutions would actually be appreciated for multiple use cases. Thank you!
Author
Owner

@davidarroyo1234 commented on GitHub (Jun 24, 2022):

Yeah, both solutions would actually be appreciated for multiple use cases. Thank you!

I was only able to do it the first way, with a blacklist.

All the people in this blacklist wont be unfollowed.

To add some username to the blacklist just follow the example of username1,username2 etc..

To execute the script copy the code as always and paste it on the console.

(REMEMBER TO PUT THE USERNAME NOT THE NAME)

const ACCOUNT_USERNAME_BLACKLIST = [
    "username1",
    "username2",
    "username3",
]


function getCookie(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2) return parts.pop().split(';').shift();
}

function sleep(ms) {
    return new Promise((resolve) => {
        setTimeout(resolve, ms);
    });
}

function afterUrlGenerator(nextCode) {
    return `https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${ds_user_id}","include_reel":"true","fetch_mutual":"false","first":"24","after":"${nextCode}"}`;
}

function unfollowUserUrlGenerator(idToUnfollow) {
    return `https://www.instagram.com/web/friendships/${idToUnfollow}/unfollow/`;
}

let csrftoken = getCookie("csrftoken");
let ds_user_id = getCookie("ds_user_id");
let initialURL = `https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${ds_user_id}","include_reel":"true","fetch_mutual":"false","first":"24"}`;

let doNext = true;
let followedPeople;
let filteredList = [];
let getUnfollowCounter = 0;
let scrollCicle = 0;

startScript();

async function startScript() {
    while (doNext) {
        let receivedData
        try {
            receivedData = await fetch(initialURL).then(res => res.json());
        } catch (e) {
            continue;
        }

        if (!followedPeople) {
            followedPeople = receivedData.data.user.edge_follow.count;
        }

        doNext = receivedData.data.user.edge_follow.page_info.has_next_page;
        initialURL = afterUrlGenerator(receivedData.data.user.edge_follow.page_info.end_cursor);
        getUnfollowCounter += receivedData.data.user.edge_follow.edges.length;


        receivedData.data.user.edge_follow.edges.forEach(x => {
            if (!x.node.follows_viewer) {
                filteredList.push(x.node);
            }
        })

        console.clear();
        console.log(`%c Progress ${getUnfollowCounter}/${followedPeople} (${parseInt((getUnfollowCounter / followedPeople) * 100)}%)`, 'background: #222; color: #bada55;font-size: 35px;');
        console.log(`%c This users don't follow you (Still in progress)`, 'background: #222; color: #FC4119;font-size: 13px;');

        filteredList.forEach(x => {
            console.log(x.username);
        })

        await sleep(Math.floor(Math.random() * (1000 - 600)) + 1000);
        scrollCicle++;
        if (scrollCicle > 6) {
            scrollCicle = 0;
            console.log(`%c Sleeping 10 secs to prevent getting temp blocked`, 'background: #222; color: ##FF0000;font-size: 35px;');

            await sleep(10000);
        }
    }

    console.clear();

    console.log(`%c ${filteredList.length} users don't follow you`, 'background: #222; color: #bada55;font-size: 25px;');

    filteredList.forEach(x => {
        console.log(x.username);
    });

    wantUnfollow = confirm("Do you want to unfollow this people we listed?");

    if (wantUnfollow) {
        let counter = 0;
        unfollowSleepCounter = 0;
        for (const x of filteredList) {
            if (x.username && !ACCOUNT_USERNAME_BLACKLIST.includes(x.username)) {
                try {
                    await fetch(unfollowUserUrlGenerator(x.id), {
                        "headers": {
                            "content-type": "application/x-www-form-urlencoded",
                            "x-csrftoken": csrftoken,
                        },
                        "method": "POST",
                        "mode": "cors",
                        "credentials": "include"
                    });
                } catch (e) {
                }

                await sleep(Math.floor(Math.random() * (6000 - 4000)) + 4000);
                counter++;
                unfollowSleepCounter++;
                if (unfollowSleepCounter >= 5) {
                    console.log(`%c Sleeping 5 minutes to prevent getting temp blocked`, 'background: #222; color: ##FF0000;font-size: 35px;');
                    unfollowSleepCounter = 0;
                    await sleep(300000)
                }
                console.log(`Unfollowed ${counter}/${filteredList.length}`)
            }
        }
        console.log(`%c All DONE!`, 'background: #222; color: #bada55;font-size: 25px;');
    } else {
        console.log(`%c All DONE!`, 'background: #222; color: #bada55;font-size: 25px;');
    }
}
<!-- gh-comment-id:1165611354 --> @davidarroyo1234 commented on GitHub (Jun 24, 2022): > Yeah, both solutions would actually be appreciated for multiple use cases. Thank you! I was only able to do it the first way, with a blacklist. All the people in this blacklist wont be unfollowed. To add some username to the blacklist just follow the example of username1,username2 etc.. To execute the script copy the code as always and paste it on the console. (REMEMBER TO PUT THE USERNAME NOT THE NAME) ``` const ACCOUNT_USERNAME_BLACKLIST = [ "username1", "username2", "username3", ] function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); } function afterUrlGenerator(nextCode) { return `https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${ds_user_id}","include_reel":"true","fetch_mutual":"false","first":"24","after":"${nextCode}"}`; } function unfollowUserUrlGenerator(idToUnfollow) { return `https://www.instagram.com/web/friendships/${idToUnfollow}/unfollow/`; } let csrftoken = getCookie("csrftoken"); let ds_user_id = getCookie("ds_user_id"); let initialURL = `https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${ds_user_id}","include_reel":"true","fetch_mutual":"false","first":"24"}`; let doNext = true; let followedPeople; let filteredList = []; let getUnfollowCounter = 0; let scrollCicle = 0; startScript(); async function startScript() { while (doNext) { let receivedData try { receivedData = await fetch(initialURL).then(res => res.json()); } catch (e) { continue; } if (!followedPeople) { followedPeople = receivedData.data.user.edge_follow.count; } doNext = receivedData.data.user.edge_follow.page_info.has_next_page; initialURL = afterUrlGenerator(receivedData.data.user.edge_follow.page_info.end_cursor); getUnfollowCounter += receivedData.data.user.edge_follow.edges.length; receivedData.data.user.edge_follow.edges.forEach(x => { if (!x.node.follows_viewer) { filteredList.push(x.node); } }) console.clear(); console.log(`%c Progress ${getUnfollowCounter}/${followedPeople} (${parseInt((getUnfollowCounter / followedPeople) * 100)}%)`, 'background: #222; color: #bada55;font-size: 35px;'); console.log(`%c This users don't follow you (Still in progress)`, 'background: #222; color: #FC4119;font-size: 13px;'); filteredList.forEach(x => { console.log(x.username); }) await sleep(Math.floor(Math.random() * (1000 - 600)) + 1000); scrollCicle++; if (scrollCicle > 6) { scrollCicle = 0; console.log(`%c Sleeping 10 secs to prevent getting temp blocked`, 'background: #222; color: ##FF0000;font-size: 35px;'); await sleep(10000); } } console.clear(); console.log(`%c ${filteredList.length} users don't follow you`, 'background: #222; color: #bada55;font-size: 25px;'); filteredList.forEach(x => { console.log(x.username); }); wantUnfollow = confirm("Do you want to unfollow this people we listed?"); if (wantUnfollow) { let counter = 0; unfollowSleepCounter = 0; for (const x of filteredList) { if (x.username && !ACCOUNT_USERNAME_BLACKLIST.includes(x.username)) { try { await fetch(unfollowUserUrlGenerator(x.id), { "headers": { "content-type": "application/x-www-form-urlencoded", "x-csrftoken": csrftoken, }, "method": "POST", "mode": "cors", "credentials": "include" }); } catch (e) { } await sleep(Math.floor(Math.random() * (6000 - 4000)) + 4000); counter++; unfollowSleepCounter++; if (unfollowSleepCounter >= 5) { console.log(`%c Sleeping 5 minutes to prevent getting temp blocked`, 'background: #222; color: ##FF0000;font-size: 35px;'); unfollowSleepCounter = 0; await sleep(300000) } console.log(`Unfollowed ${counter}/${filteredList.length}`) } } console.log(`%c All DONE!`, 'background: #222; color: #bada55;font-size: 25px;'); } else { console.log(`%c All DONE!`, 'background: #222; color: #bada55;font-size: 25px;'); } } ```
Author
Owner

@davidarroyo1234 commented on GitHub (Jul 1, 2022):

I'll close this issue for now. If you have any other question feel free to reopen it.

<!-- gh-comment-id:1172757734 --> @davidarroyo1234 commented on GitHub (Jul 1, 2022): I'll close this issue for now. If you have any other question feel free to reopen it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/InstagramUnfollowers#203
No description provided.