This is the code I made to like tweets
I am trying to make the code to like tweets but I need a set timeout thing so that i don't get banned while using
for (let i = 0; i < 5; i++)
for(var j = 1; j < 9; j++) {
for (const d of document.querySelectorAll('div[data-testid="like"]')) {
d.scrollIntoView(true);
d.click()
}};
I am trying to make a timeout but i don't know how to
I have tried to make it like this but it did not work
for (let i = 0; i < 5; i++)
for(var j = 1; j < 9; j++) {
for (const d of document.querySelectorAll('div[data-testid="like"]')) {
d.scrollIntoView(true);
await sleep({ seconds: 1 });
d.click()
}};
const sleep = ({ seconds }) =>
new Promise((proceed) => {
console.log(`WAITING FOR ${seconds} SECONDS...`);
setTimeout(proceed, seconds * 1);
});
Don't do this in a loop.
From your comments it sounds like you want a bookmarklet
javascript:(function() { const likes = document.querySelectorAll('div[data-testid=like]'); let cnt = 0; const clickLike = () => { if (cnt >= likes.length) return; const like = likes[cnt]; like.scrollIntoView(true); like.click(); cnt++; setTimeout(clickLike, 1000); }; clickLike(); })()
Example in a page
window.addEventListener("DOMContentLoaded", () => { // page is ready
const likes = document.querySelectorAll('div[data-testid=like]');
let cnt = 0;
const clickLike = () => {
if (cnt >= likes.length) return; // stop
const like = likes[cnt];
like.classList.add("clicked"); // for show
like.scrollIntoView({behavior: "smooth"});
like.click();
cnt++;
setTimeout(clickLike, 1000); // wait a second
};
clickLike(); // start
});
div[data-testid=like] {
height: 100px
}
div[data-testid=like].clicked { border: 1px solid green; }
<div data-testid="like">Like 1</div>
<div data-testid="like">Like 2</div>
<div data-testid="like">Like 3</div>
<div data-testid="like">Like 4</div>
<div data-testid="like">Like 5</div>