Skip to content

Instantly share code, notes, and snippets.

@Eskuero
Last active October 6, 2019 23:50
Show Gist options
  • Save Eskuero/c4d2a52b5ef7acae34a6667cc5ab0e1f to your computer and use it in GitHub Desktop.
Save Eskuero/c4d2a52b5ef7acae34a6667cc5ab0e1f to your computer and use it in GitHub Desktop.
Updated version of the tweet deleter and retweet undoer for the 2019 version of Twitter.
var deleteall = async function() {
console.log("Undoing Retweets")
// Keep iterating until there's no retweet to do
while (retweet = document.querySelector('[data-testid="unretweet"]')) {
console.log(retweet)
retweet.click();
// Sleep a bit to make sure the confirm prompt appeared
await new Promise(r => setTimeout(r, 1000));
document.querySelector('[data-testid="unretweetConfirm"]').click()
// Sleep a bit again to make sure the tweet is unspawned from view
await new Promise(r => setTimeout(r, 1000));
// Scroll until the end to make sure more things are loaded
window.scrollTo(0, document.querySelector('[data-testid="primaryColumn"]').clientHeight);
}
console.log("Deleting tweets")
while (tweet = document.getElementsByClassName("css-1dbjc4n r-sdzlij r-1p0dtai r-xoduu5 r-1d2f490 r-podbf7 r-u8s1d r-zchlnj r-ipm5af r-o7ynqc r-6416eg")[0]) {
console.log(tweet)
tweet.click();
// Sleep to make sure the menuitem spawned
await new Promise(r => setTimeout(r, 1000));
document.querySelector('[role="menuitem"]').parentElement.firstChild.click();
// Sleep a bit to make sure the confirm prompt appeared
await new Promise(r => setTimeout(r, 1000));
document.querySelector('[data-testid="confirmationSheetConfirm"]').click();
// Sleep a bit again to make sure the tweet is unspawned from view
await new Promise(r => setTimeout(r, 1000));
// Scroll until the end to make sure more things are loaded
window.scrollTo(0, document.querySelector('[data-testid="primaryColumn"]').clientHeight);
}
}
// Run it
deleteall();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment