Skip to content

Instantly share code, notes, and snippets.

@jadeallencook
Last active March 15, 2024 01:15
Show Gist options
  • Star 55 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save jadeallencook/139a3d5f9291c2d612d91c8b8c72a755 to your computer and use it in GitHub Desktop.
Save jadeallencook/139a3d5f9291c2d612d91c8b8c72a755 to your computer and use it in GitHub Desktop.
instagram autolike script
let likes = 0;
setInterval(() => {
const heart = document.querySelector('svg[aria-label="Like"][width="24"]');
const arrow = document.querySelector('svg[aria-label="Next"]');
if (heart) {
heart.parentNode.parentElement.click()
likes++;
console.log(`You've liked ${likes} post(s)`);
}
arrow.parentElement.parentElement.click();
}, 20000);
/*
let likes = 0;
setInterval(() => {
const heart = document.querySelector('svg[aria-label="Like"]').parentNode;
const arrow = document.querySelector("a.coreSpriteRightPaginationArrow");
if (heart) {
heart.click();
likes++;
console.log(`You've liked ${likes} post(s)`);
}
arrow.click();
}, 5000);
*/
@itsmay
Copy link

itsmay commented Aug 15, 2020

Trying to randomize between 5-10 seconds per like. Would this work?

var min = 5,
max = 10;
var rand = Math.floor(Math.random() * (max - min + 1) + min);

let likes = 0;
setTimeout(() => {
const heart = document.querySelector('svg[aria-label="Like"]');
const arrow = document.querySelector('a.coreSpriteRightPaginationArrow');
if (heart) {
heart.parentNode.click()
likes++;
console.log(You've liked ${likes} post(s));
}
arrow.click();
}, rand*1000);

@zsryals
Copy link

zsryals commented Aug 26, 2020

Doesn't the setTimeout() function only run once. So your code would run once after rand * 1000 ms instead of in intervals of rand * 1000 like it would with the setInterval() function.

@zsryals
Copy link

zsryals commented Aug 26, 2020

Even if it was changed to setInterval(), you would still face a problem since the rand*1000 in the function will stay as it is first initialized to be (the 'rand' variable will not update). (I am still new to JavaScript though (started last week) so I might be wrong).

@LucaVictor
Copy link

I've tried what you did guys, but nothing seems to be working for me. So I build my own version and it works, maybe it's helpful for you too.

let likes = 0;
setInterval(() => {

    const node_list = document.querySelectorAll('.wpO6b');
    const heart = node_list[1];
    const arrow = document.querySelector('a.coreSpriteRightPaginationArrow');

    if (heart) {
        heart.click();
        likes++;
        console.log(`You've liked ${likes} post(s)`);
    }
    arrow.click();

}, 3000);

@abrutans
Copy link

abrutans commented Jan 2, 2021

I've tried what you did guys, but nothing seems to be working for me. So I build my own version and it works, maybe it's helpful for you too.

let likes = 0;
setInterval(() => {

    const node_list = document.querySelectorAll('.wpO6b');
    const heart = node_list[1];
    const arrow = document.querySelector('a.coreSpriteRightPaginationArrow');

    if (heart) {
        heart.click();
        likes++;
        console.log(`You've liked ${likes} post(s)`);
    }
    arrow.click();

}, 3000);

Try checking the element names, they might have changed.

@billiondollar023
Copy link

But how do we login? Can you give us the starting line of code

@BerkCald
Copy link

That's great!

@asdbukhari
Copy link

how to use this

@tospi
Copy link

tospi commented May 31, 2021

Is there a function for automatic comments?
And a function for a random like interval?

@fotini1
Copy link

fotini1 commented Nov 8, 2021

Thank you @jadeallencook for the script!
Unfortunately, it has stopped working for me. Maybe Instagram changed something.

@Sercalod
Copy link

let likes = 0;
let autoLike = setInterval(() => {
    const heart = document.querySelector('svg[aria-label="Like"]');
    const arrow = document.querySelector('svg[aria-label="Next"]');
    if (heart) {
        heart.parentNode.click();
        likes++;
        console.log(`You've liked ${likes} post(s)`);
    }
    arrow.parentElement.click();
}, 5000);

I edited the code very little.
I have put the "setInterval" inside a variable, so that it can be stopped by writing:
clearInterval(autoLike);

@microhacker0891
Copy link

can somebody elabrate how to use the code

@maxeth
Copy link

maxeth commented Dec 25, 2021

@microhacker0891 Open an Instagram post, copy and paste it inside your browser’s console and click enter or use a browser extension like Tempermonkey

@microhacker0891
Copy link

microhacker0891 commented Dec 25, 2021 via email

@maxeth
Copy link

maxeth commented Dec 25, 2021

@microhacker0891 Just open some post on Instagram where you have an arrow to go to the next post, press F12 on your keyboard, then switch to the tab Console, paste the code above into the console, and press Enter on your keyboard to run the script.

@microhacker0891
Copy link

microhacker0891 commented Dec 25, 2021 via email

@microhacker0891
Copy link

microhacker0891 commented Dec 25, 2021 via email

@gabrielaequiz
Copy link

OMG i just want to say THANK YOU !!!! this is so good :) Does anyone know how many likes does Instagram let you do before they ban you ? how long do you guys run this code for ?

@uykhangung
Copy link

uykhangung commented Jan 13, 2022 via email

@hymandco
Copy link

dont have any auto follow ?

@HypnoticLOL
Copy link

HypnoticLOL commented Feb 21, 2022

this should work, wrote it cuz I have noting better to do, dosnt press next button till its liked. also has a random interval between 1 second to 5 seconds so IG dosnt see it as a bot

var random = Math.random()*(5000-1000+1)+10;
var likes = 0;        
function NB(){
    //next button
    var element = document.querySelector('svg[aria-label="Next"]')
    if(typeof(element) != 'undefined' && element != null){
        console.log('Element exists!');
        document.querySelector('svg[aria-label="Next"]').parentElement.parentElement.click();
        likes = likes + 1;
    } else{
        alert(`You Liked ${likes} likes post(s)`);
        clearInterval(likeBtn);
    }
}
var likeBtn = setInterval(like, random);
function like(){
//like button
    var element = document.getElementsByClassName('QBdPU rrUvL')
    if(typeof(element) != 'undefined' && element != null){
        var classes = document.getElementsByClassName('QBdPU rrUvL');
        var Rate = classes[0];
        Rate.click();
        setTimeout(function(){
            NB();
        }, random)
    } else{
        
    }
}

@PassCody
Copy link

PassCody commented Mar 3, 2022

Unfortunately instagram added a like spam filter.

You need to set the timer higher then 5 seconds.

Here is my 2022 Working Script:

let likesGiven = 0;
setInterval(() => {
let heart = document.getElementsByClassName("fr66n")[0].getElementsByClassName("wpO6b")[0],
arrow = document.getElementsByClassName(" l8mY4 feth3")[0].getElementsByClassName("wpO6b")[0];
if (heart) {
likesGiven++;
heart.click();
}
arrow.click();
console.log('You've liked ${likesGiven} post(s)!');
}, 7500);

The last picture gets liked and unliked again and again. So the page has to be reloaded and the last like set manually. If someone likes to optimize the script so that it stops at the last frame after the like, feel free to do it and share it.

@devlillious
Copy link

devlillious commented May 21, 2022

For those still looking for a properly working solution:

// Profile data
const profile = {
    posts: parseInt(document.getElementsByClassName("g47SY")[0].textContent),
    username: document.getElementsByClassName("_7UhW9")[0].textContent,
    index: 0
}

// Check if user is on the correct page, if not, attempt to redirect to the correct page.
IG_Check = () => {
    if (!profile.posts) return console.error("Error: Posts could not be found. Are you on the right page?");
    if (!profile.username) return console.error("Error: Username could not be found. Are you on the right page?");
    if (typeof profile.posts != "number") return console.error("Error: TotalPosts is not a number which means the class name has probably changed.");
    if (profile.posts < 1) return console.warn("Warning: There are not posts to like.");

    const _Location = window.location.href;
    if (_Location.slice(_Location.length - 6 - profile.username.length) != `${profile.username}/feed/`) {
        alert("This script is running on the incorrect page and will attempt to navigate to the correct page. You will need to reload this script.");
        window.location.href = `https://www.instagram.com/${profile.username}/feed/`;
    };
}

// Generates a random time above 7500
randomTime = () => {
    console.time("Timeout");
    return Math.random() * ((Math.random() * 5000) / Math.PI) + 7500;
}

// Prints user profile data
IG_PrintProfile = () => {
    console.log(`Instagram Autoliker by @Lillious`);
    console.log(`Username: ${profile.username}`);
    console.log(`Total Posts: ${profile.posts}`);
}

// Autolike function
IG_AutoLike = () => {
    setTimeout(() => {
        if (profile.index >= profile.posts) return console.log("Finished auto liking.");
        profile.index++;
        window.scrollTo(0, document.body.scrollHeight);
        let like = document.getElementsByClassName("fr66n")[profile.index].getElementsByClassName("wpO6b")[0];
        if (like) {
            like.click();
        } else {
            return console.error("Error: Like button could not be found.");
        }
        console.log(`Posts Liked: ${profile.index}/${profile.posts}`);
        console.timeEnd("Timeout");
        IG_AutoLike();
    }, randomTime());
};

IG_Check();
IG_PrintProfile();
IG_AutoLike();

@demoaccountdfe545
Copy link

amazing broooo!

@tospi
Copy link

tospi commented Mar 8, 2023

How can I activate the script. What exactly do i have to do?

@PassCody
Copy link

PassCody commented Mar 8, 2023

How can I activate the script. What exactly do i have to do?

Pre-condition: using a Computer not a Mobile/Smart Phone.

Open you Dev Tool and paste it in the console there. You can open the Dev Tool in the most Browsers with F12 or CTRL + SHIFT + I or J. Not Sure about the last one. I use Opera GX as Browser.

@tospi
Copy link

tospi commented Mar 8, 2023

In a instagram hashtag i click on a image and then I copied the code from devlillious in the console. But i get e error. 🤷🏼‍♂️

@PassCody
Copy link

PassCody commented Mar 8, 2023

In a instagram hashtag i click on a image and then I copied the code from devlillious in the console. But i get e error. 🤷🏼‍♂️

Can you try mine? But I need to warn you. Thouse Auto Like Scripts are Forbidden and can cause a permanently ban from Instagram. So be careful by using them.

Instagram is constantly evolving to prevent botting and scripting. Does the classes and IDs of Instagram call each other again and again.

@Lillious
Copy link

Lillious commented Mar 8, 2023

In a instagram hashtag i click on a image and then I copied the code from devlillious in the console. But i get e error. 🤷🏼‍♂️

I'm devlillious, just a new account for work.
My code most likely doesn't work anymore. It did at one point but like @PassCody stated, instagram is constantly evolving and changing their code.

@zone0119
Copy link

zone0119 commented May 8, 2023

Hello, I wrote some code you can use https://github.com/zone0119/instalike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment