Code Monkey home page Code Monkey logo

Comments (4)

davidarroyo1234 avatar davidarroyo1234 commented on July 29, 2024

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.

from instagramunfollowers.

shiner66 avatar shiner66 commented on July 29, 2024

from instagramunfollowers.

davidarroyo1234 avatar davidarroyo1234 commented on July 29, 2024

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;');
    }
}

from instagramunfollowers.

davidarroyo1234 avatar davidarroyo1234 commented on July 29, 2024

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

from instagramunfollowers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.