Skip to content

Instantly share code, notes, and snippets.

@vijayhardaha
Created March 14, 2025 00:51
Show Gist options
  • Save vijayhardaha/93531e38175d9a63eed0d835f3370e07 to your computer and use it in GitHub Desktop.
Save vijayhardaha/93531e38175d9a63eed0d835f3370e07 to your computer and use it in GitHub Desktop.
Instagram Auto-Like Script

This JavaScript code automatically likes all posts on Instagram by clicking the "Like" buttons at 2-second intervals. Once all posts are liked, an alert will notify the user that the task is complete. This script targets Instagram's DOM structure and ensures each like action is performed with a slight delay for a smooth user experience.

Code:

var elements = document.querySelectorAll('article section div[role="button"][tabindex="0"] svg title');
var likeButtons = [];

elements.forEach(function(el) {
    if (el.innerHTML.toLowerCase().trim() === 'like') {
        var parent = el.closest('div[role="button"][tabindex="0"]');
        if (parent) {
            likeButtons.push(parent);
        }
    }
});

likeButtons.forEach(function(button, index) {
    setTimeout(function() {
        button.click();
        console.log('Clicked element ' + (index + 1));

        // Show an alert when all posts are clicked
        if (index === likeButtons.length - 1) {
            setTimeout(function() {
                alert('All posts have been liked!');
            }, 1000); // Slight delay after the last click for better UX
        }
    }, index * 2000); // Delay each click by 2 seconds
});

How It Works:

  1. Selects all like buttons on Instagram posts using specific DOM selectors.
  2. Filters out "Like" buttons based on their inner HTML content.
  3. Identifies the closest parent div with the role="button" and tabindex="0" attributes, which corresponds to the clickable like button.
  4. Clicks each like button sequentially with a 2-second delay between each click.
  5. Displays an alert once all posts have been liked, with a slight delay after the last click for a smooth experience.

This script is perfect for automating the liking process on Instagram posts while ensuring an orderly and user-friendly execution.

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