Skip to content

Instantly share code, notes, and snippets.

@tokozedg
Created October 26, 2023 16:30
Show Gist options
  • Save tokozedg/d600c679e13338fdef48641b1563653f to your computer and use it in GitHub Desktop.
Save tokozedg/d600c679e13338fdef48641b1563653f to your computer and use it in GitHub Desktop.
twitter liker script
// open a trend and run this in web console to like all latest tweets
let maxLikes = 150;
let totalLikes = 0;
let usernames = [];
let loopCount = 0;
function autoLike(index) {
const tweets = document.querySelectorAll('[data-testid="tweet"]');
const tweet = tweets[index];
if (tweet && loopCount <= 10) {
loopCount++;
const likeButton = tweet.querySelector('[data-testid="like"] > div');
const userNameElement = tweet.querySelector('[data-testid="User-Name"]');
const userName = userNameElement.children[1].querySelector('a').textContent.trim();
if (!usernames.includes(userName)) {
const randomDelay = Math.floor(Math.random() * (10000 - 3000 + 1)) + 3000; // Random delay between 3 to 10 seconds
setTimeout(() => {
likeButton.click(); // Click on the first child div inside data-testid="like"
totalLikes++;
usernames.push(userName);
console.log(`Liked post from ${userName}. Total likes: ${totalLikes}`);
console.log(`Usernames array: ${usernames}`);
autoLike(index + 1); // Call the function recursively for the next tweet
}, randomDelay);
} else {
autoLike(index + 1); // Call the function recursively for the next tweet
}
} else {
loopCount = 0;
var firstTab = document.querySelectorAll('a[role="tab"]')[0];
firstTab.click();
// Wait for 3 seconds (3000 milliseconds)
setTimeout(function() {
// Select the second <a> element with role=tab
var secondTab = document.querySelectorAll('a[role="tab"]')[1];
// Click on the second tab after 3 seconds
secondTab.click();
}, 3000);
window.scrollTo(0, 0); // Scroll to the top of the page
console.log('Finished 10 loops or no more tweets to like. Will restart in 5');
console.log(`Total likes done: ${totalLikes}`);
console.log(`Usernames array: ${usernames}`);
if(totalLikes < maxLikes){
setTimeout(() => {
autoLike(0); // Start liking tweets again after waiting for 5 seconds
}, 5000);
};
}
}
autoLike(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment