OpenSourceHelpCommunity / Questions

To add your question raise an issue in this repository.
MIT License
27 stars 47 forks source link

BOT TWITTER JAVASCRIPT #463

Open zedkurd opened 6 months ago

zedkurd commented 6 months ago

Hi, I wanted a bot that could run on chrome console without using API, username and password, that would automatically create custom comments for users on Twitter's timeline or home page, and not reply to my own comments. This is my code in response. Clicks but does not comment. // Function to click the reply button on a tweet function clickReplyButton(tweet) { const replyButton = tweet.querySelector('div[data-testid="reply"]'); if (replyButton) { replyButton.click(); } }

// Function to type a comment and submit async function typeComment(commentText) { const commentBox = document.querySelector('div[data-testid="tweetTextArea_0"]'); if (commentBox) { commentBox.focus(); document.execCommand('insertText', false, commentText);

    // Wait for the comment to be typed
    await new Promise(resolve => setTimeout(resolve, 500));

    const tweetButton = document.querySelector('div[data-testid="tweetButton"]');
    if (tweetButton) {
        tweetButton.click();
    }
}

}

// Function to comment on timeline tweets async function commentOnTimeline() { const tweets = document.querySelectorAll('article[data-testid="tweet"]');

for (const tweet of tweets) {
    clickReplyButton(tweet);

    // Wait for the reply box to appear
    await new Promise(resolve => setTimeout(resolve, 1000));

    typeComment('Hello');

    // Wait for the comment to be posted
    await new Promise(resolve => setTimeout(resolve, 2000));
}

}

// Run the bot commentOnTimeline()