Skip to content

Instantly share code, notes, and snippets.

@raghav4
Last active December 10, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raghav4/66f2d222c4a0badb1fa9143d03e3cfd9 to your computer and use it in GitHub Desktop.
Save raghav4/66f2d222c4a0badb1fa9143d03e3cfd9 to your computer and use it in GitHub Desktop.
Script to like all the Instagram posts!
function doSomething(random) {
var firstLike = document.querySelector(
'section.ltpMr.Slqrh > span.fr66n > button > div > span > svg[aria-label="Like"]'
);
if (firstLike) {
firstLike.scrollIntoView({
behavior: "smooth",
block: "center",
inline: "nearest",
});
var closestElement = firstLike.closest("button");
console.log("clicked...\n");
closestElement.click();
}
console.log("waiting for " + random + " miliseconds\n");
}
(function loop() {
var min = 1000; // min 1 second
var max = 2000; // max 2 seconds
var random = Math.floor(Math.random() * (+max - +min)) + +min;
var today = new Date().getHours();
console.log("current hour: " + today + "\n");
var start = 9; // start liking after this hour
var end = 20; // stop liking after this hour
if (today >= start && today <= end) {
// Between
// On
setTimeout(function () {
doSomething(random);
loop();
}, random);
} else {
// Off
if (start < today) {
var diff = start - today;
} else {
var diff = today - start;
}
console.log("diff * 3600000: " + Math.abs(diff) * 3600000 + "\n");
console.log(
"waiting for " + Math.abs(diff) + " hours until " + start + "\n"
);
setTimeout(function () {
loop();
}, Math.abs(diff) * 3600000);
}
})();
@raghav4
Copy link
Author

raghav4 commented Dec 10, 2020

Without Scroll

let likes = 0;
setInterval(() => {
  const heart = document.querySelector('svg[aria-label="Like"]');
  const arrow = document.querySelector("a.coreSpriteRightPaginationArrow");
  if (heart) {
    heart.parentNode.click();
    likes++;
    console.log(`You've liked ${likes} post(s)`);
  }
  arrow.click();
}, 3000);

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