Last active
January 31, 2025 15:12
-
-
Save christopherwoodall/b2382ef0add0ad707cbc88140005dae8 to your computer and use it in GitHub Desktop.
Delete tweets
This file contains hidden or 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
// source: https://x.com/ThinkWiselyMatt/status/1885076017414348830 | |
(async () => { | |
const delay = ms => new Promise(res => setTimeout(res, ms)); | |
let deletedCount = 0; | |
const maxDeletes = 2000; // Adjust as needed | |
while (deletedCount < maxDeletes) { | |
let posts = document.querySelectorAll('[data-testid="tweet"]'); | |
if (posts.length === 0) { | |
console.log("No more posts found. Scrolling..."); | |
window.scrollTo(0, document.body.scrollHeight); | |
await delay(1000); | |
continue; | |
} | |
for (let post of posts) { | |
if (deletedCount >= maxDeletes) { | |
console.log(`Reached max limit of ${maxDeletes}. Stopping.`); | |
return; | |
} | |
let timestamp = post.querySelector('time')?.getAttribute('datetime'); | |
if (!timestamp) continue; | |
let postDate = new Date(timestamp); | |
let now = new Date(); | |
let hoursOld = (now - postDate) / (1000 * 60 * 60); | |
if (hoursOld < 48) { | |
console.log("Skipping recent post (<48 hours old)."); | |
continue; | |
} | |
let postText = post.innerText || "[Text not found]"; | |
let isQuoteTweet = post.querySelector('[data-testid="tweetText"] + div'); | |
let retweetButton = post.querySelector('[data-testid="unretweet"]'); // This button exists if it's a repost | |
if (isQuoteTweet) { | |
console.log(`Found Quote Tweet: "${postText}"`); | |
} | |
if (retweetButton) { | |
console.log(`Found Repost: "${postText}". Attempting to undo...`); | |
http://retweetButton.click(); | |
await delay(500); | |
let confirmUndoRepost = document.querySelector('div[data-testid="unretweetConfirm"]'); | |
if (confirmUndoRepost) { | |
http://confirmUndoRepost.click(); | |
console.log(`"${postText}" - REPOST UNDONE`); | |
deletedCount++; | |
console.log(`Deleted ${deletedCount} items. Waiting 0.5 seconds...`); | |
await delay(500); | |
continue; | |
} else { | |
console.log("Undo Repost confirmation button not found."); | |
continue; | |
} | |
} | |
let caret = post.querySelector('[data-testid="caret"]'); | |
if (!caret) continue; | |
http://caret.click(); | |
await delay(500); | |
let deleteOption = [...document.querySelectorAll('div[role="menuitem"]')] | |
.find(el => el.innerText.includes("Delete")); | |
if (deleteOption) { | |
http://deleteOption.click(); | |
await delay(500); | |
let confirmDelete = document.querySelector('button[data-testid="confirmationSheetConfirm"]'); | |
if (confirmDelete) { | |
http://confirmDelete.click(); | |
console.log(`"${postText}" - DELETED`); | |
deletedCount++; | |
console.log(`Deleted ${deletedCount} items. Waiting 0.5 seconds...`); | |
await delay(500); | |
} else { | |
console.log("Delete confirmation button not found."); | |
} | |
} | |
} | |
console.log("Scrolling for more posts..."); | |
window.scrollTo(0, document.body.scrollHeight); | |
await delay(1000); | |
} | |
console.log("Finished deleting all tweets, quotes, and reposts."); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment