Skip to content

Instantly share code, notes, and snippets.

@resultakak
Forked from antlionguard/twitter-remove-retweets.js
Last active July 5, 2025 07:27
Show Gist options
  • Save resultakak/5de8b009a3d04cef18c050c5c26ab62f to your computer and use it in GitHub Desktop.
Save resultakak/5de8b009a3d04cef18c050c5c26ab62f to your computer and use it in GitHub Desktop.
With this script, you can remove all retweets you are retweeted on Twitter.
function scrollToLoadMore() {
// keep scrolling if twitter tries to stop loading more.
// scroll up, then down to force infinite load.
window.scrollTo(0, 0);
setTimeout(function() {
window.scrollBy(0, 9999999999);
}, 200);
}
function removeTweet(tweetEl) {
// show it
tweetEl.style.backgroundColor = 'rgba(255,0,0,0.5)';
tweetEl.scrollIntoView();
window.scrollBy(0, -150);
// remove it
setTimeout(function() {
tweetEl.parentNode.removeChild(tweetEl);
}, 800);
}
function removeFav() {
let buttonEl = document.querySelector('[data-testid="unlike"]');
if(buttonEl) {
let tweetEl = buttonEl.closest('article');
if(tweetEl) {
buttonEl.click();
removeTweet(tweetEl);
}
} else {
console.log('No Tweets found');
scrollToLoadMore();
}
}
let unfavInterval = setInterval(removeFav, 4000);
const timer = ms => new Promise(res => setTimeout(res, ms));
// Unretweet normally
const unretweetTweet = async (tweet) => {
await tweet.querySelector('[data-testid="unretweet"]').click();
await timer(250);
await document.querySelector('[data-testid="unretweetConfirm"]').click();
console.log('****// Unretweeted Successfully //****')
}
// Sometimes twitter shows your retweet but green retweet button is invisible and therefore you need to retweet again for make unreweet. This function is for that.
const unretweetUnretweetedTweet = async (tweet) => {
await tweet.querySelector('[data-testid="retweet"]').click();
await timer(250);
await document.querySelector('[data-testid="retweetConfirm"]').click();
console.log('****// Retweeted Successfully //****')
await timer(250);
unretweetTweet(tweet);
}
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.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
tweetWrapper.scrollIntoView();
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