Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vadykoo/b560200a930639f8224d8715eb3aff45 to your computer and use it in GitHub Desktop.
Save vadykoo/b560200a930639f8224d8715eb3aff45 to your computer and use it in GitHub Desktop.
With this script, you can remove all retweets you are retweeted on Twitter.
const timer = ms => new Promise(res => setTimeout(res, ms));
// Unretweet normally
const unretweetTweet = async (tweet) => {
const unretweetButton = tweet.querySelector('[data-testid="unretweet"]');
if (unretweetButton) {
await unretweetButton.click();
await timer(250);
const unretweetConfirmButton = document.querySelector('[data-testid="unretweetConfirm"]');
if (unretweetConfirmButton) {
await unretweetConfirmButton.click();
console.log('****// Unretweeted Successfully //****');
} else {
console.log('****// Unretweet Confirm Button Not Found //****');
}
} else {
console.log('****// Unretweet Button Not Found //****');
}
}
// Sometimes Twitter shows your retweet but the green retweet button is invisible and therefore you need to retweet again to unretweet. This function is for that.
const unretweetUnretweetedTweet = async (tweet) => {
const retweetButton = tweet.querySelector('[data-testid="retweet"]');
if (retweetButton) {
await retweetButton.click();
await timer(250);
const retweetConfirmButton = document.querySelector('[data-testid="retweetConfirm"]');
if (retweetConfirmButton) {
await retweetConfirmButton.click();
console.log('****// Retweeted Successfully //****');
await timer(250);
await unretweetTweet(tweet);
} else {
console.log('****// Retweet Confirm Button Not Found //****');
}
} else {
console.log('****// Retweet Button Not Found //****');
}
}
setInterval(async () => {
// Get all tweets
const retweetedTweetList = document.querySelectorAll('[data-testid="socialContext"]');
console.log('****// Retweeted Tweet List Collected //****');
for (const retweet of retweetedTweetList) {
const tweetWrapper = retweet.closest('article');
tweetWrapper.scrollIntoView();
const bookmarkBtn = tweetWrapper.querySelector("button[aria-label='Bookmark']");
if (bookmarkBtn && confirm("Add to Bookmarks?")) bookmarkBtn.click();
const isRetweeted = tweetWrapper.querySelector('[data-testid="unretweet"]');
if (isRetweeted) {
console.log('****// Green Retweet Button Found - Starting "unretweetTweet" process //****');
await unretweetTweet(tweetWrapper);
} else {
console.log('****// Green Retweet Button Not Found - Starting "unretweetUnretweetedTweet" process //****');
await unretweetUnretweetedTweet(tweetWrapper);
}
await timer(2000);
}
console.log('****// List Completed //****');
console.log('****// Scrolling //****');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
await window.scrollTo(0, document.body.scrollHeight);
}, 60000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment