-
-
Save rstriquer/65bac13d19e30d422832106e3398d05b to your computer and use it in GitHub Desktop.
Scripts that auto likes posts on instagram via tag.
This file contains hidden or 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
// javascript function to use on terminal. | |
// based on code from https://gist.github.com/jadeallencook/139a3d5f9291c2d612d91c8b8c72a755 | |
// more to considere: https://www.youtube.com/watch?v=yM0NIZ6wbEc | |
// script do login: https://github.com/mateovrb/instafollow | |
// script feito em phyton https://www.youtube.com/watch?v=0PdIP2Q2X4U | |
/** | |
* Get element by XPath | |
* - Get the xpath thrught the browser and use it to select that element. | |
* @param string path | |
*/ | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
/** | |
* Tempo de espera em segundos. | |
* - Se não for repassado então o valor será calculado; | |
* @param int max | |
* @param int min | |
*/ | |
function sleep(max = 6, min = 4) { | |
return new Promise( | |
resolve => setTimeout( | |
resolve, | |
Math.floor(Math.random() * (max - min + 1) + min) * 1000 | |
) | |
); | |
} | |
function isVisible( elem ) { | |
return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); | |
}; | |
async function goLike() { | |
let timeStart = new Date(); | |
// contabiliza a quantidade de imagens que polou para evitar serem muitas. | |
let countJunp = 0; | |
// random maxLikes per round | |
let saw = 0, likes = 0 | |
/** | |
* maxLikes should be between 200 to 500 (200 + 300) | |
*/ | |
let maxLikes = Math.floor(Math.random() * 500 + 200); | |
var rand, multiImage, video, heart, arrow, commentIntput; | |
console.log(`Going for ${maxLikes} likes!`); | |
do { | |
multiImage = getElementByXpath('/html/body/div[4]/div[2]/div/article/div[2]/div/div[1]/div[2]/div/button'); | |
video = document.querySelector('video'); | |
heart = document.querySelector('svg[aria-label="Like"]'); | |
arrow = document.querySelector('a.coreSpriteRightPaginationArrow'); | |
commentIntput = document.querySelector('textarea[placeholder="Add a comment…"]'); | |
saw++; | |
// try to decide if is it a vídeo | |
if (!video) { | |
video = document.querySelector('span[aria-label="Play"]'); | |
} | |
if (video) { | |
console.log('video'); | |
} | |
if (!video) { | |
if (multiImage) { | |
// try to pass all imagens on a multiImage | |
do { | |
await sleep(4, 2); | |
multiImage.click(); | |
console.log('next image!') | |
} while (isVisible(multiImage)); | |
await sleep(2, 1); | |
} | |
if (heart && Math.floor(Math.random() * 100) % 2 == 0) { | |
await sleep(); | |
heart.parentNode.click() | |
likes++; | |
timeTotal = Math.abs(((timeStart - new Date()) / 1000) / 60) | |
console.log(`Liked ${likes}/${saw} post(s) (${maxLikes - likes} to go) in ${timeTotal}min`); | |
// random sleep to click next | |
await sleep(1, 0, 5); | |
} | |
} | |
// random like picture | |
if (!arrow) { | |
console.log('You must open up a picture for this to work!') | |
break; | |
} | |
arrow.click(); | |
// random sleep to check for the picture | |
await sleep(); | |
} while (likes < maxLikes); | |
timeTotal = Math.abs(((timeStart - new Date()) / 1000) / 60) | |
console.log(`Donne - Liked:${likes}; saw:${saw}; maxLikes:${maxLikes}) in ${timeTotal}min`); | |
} | |
goLike(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment