Script to delete all X / Twitter tweets. (Credits go to ChatGPT, I didn't write any of this code)
- Open Chrome and go to your X profile (https://x.com/USERNAME/with_replies)
- Open Chrome Developer Console. Copy/Paste the code:
const deleteAllTweets = async () => {
const processedButtons = new Set();
const getDeleteButtons = () => Array.from(document.querySelectorAll('[data-testid="tweet"] [data-testid="caret"]'));
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
while (true) {
const deleteButtons = getDeleteButtons().filter(button => !processedButtons.has(button));
if (deleteButtons.length === 0) break;
for (const button of deleteButtons) {
processedButtons.add(button);
button.click();
await delay(250);
const menuItems = Array.from(document.querySelectorAll('[role="menuitem"]'));
const deleteOption = menuItems.find(item => item.textContent === 'Delete');
if (deleteOption) {
deleteOption.click();
document.querySelector('[data-testid="confirmationSheetConfirm"]')?.click();
await delay(3000);
} else {
const tweetContainer = button.closest('[data-testid="tweet"]');
const unretweetButton = tweetContainer?.querySelector('[data-testid="unretweet"]');
if (unretweetButton) {
unretweetButton.click();
await delay(250);
document.querySelector('[data-testid="unretweetConfirm"]')?.click();
await delay(3000);
}
}
}
}
console.log('All tweets deleted successfully!');
};
deleteAllTweets();