Last active
January 7, 2021 18:10
-
-
Save EdThePro101/4d935b3e6b0ea465c4eb4ca56fbed10c to your computer and use it in GitHub Desktop.
A simple implementation of an Instagram bot that likes photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2020 Edwin Pratt | |
// | |
// The author of this file is not responsible for any problems this script may cause. | |
// This file was created as toy while learning JavaScript. | |
// | |
// ------------------------------ | |
// | |
// I was always interested in bots and how they work. So I created this simple bot that will like photos on Instagram. | |
// | |
// To use this script, go to https://instagram.com and login. | |
// Search for a tag like #family or go to a user's profile. | |
// Tap on the first photo/video which you see. | |
// Open the Developer Tools (Ctrl + Shift + I on Windows). | |
// Go to the JavaScript Console. | |
// Paste the code and press enter. | |
// When you're ready to start the bot, type start() and press enter. | |
// To stop the bot, type stop() and press enter. | |
// | |
// There is a variable called interval. This variable is used to set the interval in between each click | |
// On the like button. | |
// By default, it is on 5000 milliseconds (or 5 seconds). Adjust the value as needed if you have a slow connection. | |
// It is recommended that you don't go below 5000. | |
// | |
// ---------- COPY EVERYTHING BELOW THIS LINE! ----------- // | |
// Set the interval for the timer. | |
// If you have a slow connection, increase this value to 10000 (Or 10 seconds). | |
// Otherwise, don't change it. | |
const interval = 5000; | |
// Start the bot. | |
const start = () => { | |
// This variable will keep track with the number of images that have been liked. | |
let count = 0; | |
// Do not run the bot if it is already running. | |
if (typeof window.idForBot != 'undefined') { | |
console.error('The bot is already running. Run `stop()` to stop the bot.'); | |
return; | |
} | |
window.idForBot = setInterval(() => { | |
try { | |
// Select the DOM elements. | |
const arrow = document.querySelector('.coreSpriteRightPaginationArrow'); | |
const heart = document.querySelector('svg[aria-label="Like"]').parentNode.parentNode.parentNode; // IG updated HTML | |
// If the heart icon exists, click it. | |
if (typeof heart != 'undefined' && heart != null) { | |
heart.parentNode.click(); | |
count++; | |
} else { | |
throw 'Can not find the heart icon'; | |
} | |
// If there is an arrow, click it and output the number of images that have been liked. | |
// Otherwise, inform the user that he/she needs to tap on an image first. | |
if (typeof arrow != 'undefined' && arrow != null) { | |
arrow.click(); | |
console.log(`You liked ${count} photos!`); | |
} else { | |
throw 'Please tap on an image in order to run the bot...'; | |
} | |
} catch (error) { | |
console.error(error); | |
} | |
}, interval); | |
}; | |
// Stop the bot. | |
const stop = () => { | |
if (typeof window.idForBot != 'undefined') { | |
clearInterval(window.idForBot); | |
window.idForBot = undefined; | |
} else { | |
console.error('The bot is not running. Run `start()` to start the bot.'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment