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.
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
});
- Selects all like buttons on Instagram posts using specific DOM selectors.
- Filters out "Like" buttons based on their inner HTML content.
- Identifies the closest parent div with the
role="button"
andtabindex="0"
attributes, which corresponds to the clickable like button. - Clicks each like button sequentially with a 2-second delay between each click.
- 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.