Skip to content

Instantly share code, notes, and snippets.

@squio
Last active May 9, 2023 16:05
Show Gist options
  • Save squio/131e0c5fcb783ae261a2471cae75ed6a to your computer and use it in GitHub Desktop.
Save squio/131e0c5fcb783ae261a2471cae75ed6a to your computer and use it in GitHub Desktop.
Delete all your tweets and retweets from your browser's debug console
// Delete all your tweets and retweets (based on https://stackoverflow.com/a/74878105/885397)
// 1. Open Inspector in your browser
// 2. Switch to the Console tab
// 3. Copy and paste the code below after the >> prompt
// 4. leave your browser tab open, sit back and enjoy seeing all your tweets going one by one ;-)
(async () => {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let found;
let count = 0;
while (found = document.querySelectorAll('[data-testid="caret"]').length) {
// get first tweet
let tweet = document.querySelectorAll('[data-testid="tweet"]')[0];
// if it is a retweet, undo it
if (tweet.querySelectorAll('[data-testid="unretweet"]').length) {
tweet.querySelectorAll('[data-testid="unretweet"]')[0].click()
await sleep(1000)
document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click()
await sleep(1000)
}
// is a tweet
else {
tweet.querySelectorAll('[data-testid="caret"]')[0].click()
await sleep(1000)
document.querySelectorAll('[role="menuitem"]')[0].click()
await sleep(1000)
document.querySelectorAll('[data-testid="confirmationSheetConfirm"]')[0].click()
}
count++;
document.querySelector('title').innerHTML = `${count} deleted`;
}
if (!found) {
console.log('No more tweets found');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment