Last active
November 11, 2024 21:42
-
-
Save donmccurdy/c7dbf813e64e2af9c745f9f446c1ee90 to your computer and use it in GitHub Desktop.
Delete Tweets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To delete tweets, navigate to your Twitter/X profile, open your browser's JavaScript console, and paste the script below. | |
async function sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)) | |
} | |
async function deleteTweets() { | |
const tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1].textContent; | |
console.log('Remaining: ', tweetsRemaining); | |
window.scrollBy(0, 10000); | |
for (const tweetEl of document.querySelectorAll('article[data-testid="tweet"]')) { | |
tweetEl.scrollIntoView(); | |
await sleep(50); | |
const contextEl = tweetEl.querySelector('[data-testid="socialContext"]') | |
if (contextEl && contextEl.textContent === 'You reposted') { | |
// retweets | |
const unretweetEl = document.querySelector('[data-testid="unretweet"]') | |
unretweetEl.click() | |
await sleep(50); | |
const confirmEl = document.querySelector('[data-testid="unretweetConfirm"]'); | |
confirmEl.click() | |
await sleep(50); | |
} else { | |
// tweets | |
const menuEl = tweetEl.querySelector('[aria-label="More"]') | |
menuEl.click() | |
await sleep(50); | |
for (const spanEl of document.querySelectorAll('[data-testid=Dropdown] span')) { | |
if (spanEl.textContent === 'Delete') { | |
spanEl.click() | |
await sleep(50); | |
const confirmEl = document.querySelector('button[data-testid="confirmationSheetConfirm"]'); | |
confirmEl.click(); | |
await sleep(50); | |
break; | |
} | |
} | |
} | |
} | |
setTimeout(deleteTweets, 4000); | |
} | |
deleteTweets(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment