Last active
February 16, 2021 15:08
-
-
Save itsmnthn/6c6aa104651d2224ecc4a76dc49357fe to your computer and use it in GitHub Desktop.
Instagram feed and discover post liker
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
/** | |
* @author Manthankumar Satani <satanimanthan@gmail.com> | |
* @version 1.1.0 | |
*/ | |
function getLikeButtons($x, xpath) { | |
var items = []; | |
$x(xpath).forEach(item => { | |
if ( | |
item.childNodes[0].childNodes[0].childNodes[0].getAttribute( | |
"aria-label" | |
) === "Like" | |
) | |
items.push(item); | |
}); | |
return items; | |
} | |
async function startLiking($x) { | |
var likes = 0; | |
setInterval(async function() { | |
window.scrollTo(0, top); | |
top += scrollGap; | |
var xpath = '//span[@class="fr66n"]/button'; | |
var likeButtons = getLikeButtons($x, xpath); | |
likeButtons.forEach(async btn => { | |
// if (Math.floor(Math.random() * 2) + 1 === 1) { | |
btn.scrollIntoView(); | |
btn.click(); | |
likes += 1; | |
// } | |
}); | |
console.log("Liked", likes); | |
}, batchInterval); | |
} | |
var top = 0; | |
var scrollGap = 1000; | |
var batchInterval = 60000; | |
// Need to inject the $x form window object | |
startLiking(window.$x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment