Skip to content

Instantly share code, notes, and snippets.

@ezy
Forked from Eskuero/deletealltwitter.js
Last active December 17, 2019 00:31
Show Gist options
  • Save ezy/3199ca1c89580689b851ac0a25db2771 to your computer and use it in GitHub Desktop.
Save ezy/3199ca1c89580689b851ac0a25db2771 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() {
// The position of the "Delete" menuitem is +1 on search pages
position = 0 + document.location.toString().includes("search?q=")
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.querySelectorAll('[role="menuitem"]')[position].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