Skip to content

Instantly share code, notes, and snippets.

@fersandiP
Last active July 8, 2021 04:47
Show Gist options
  • Save fersandiP/ae4ca417f1091118767a8ea3dd8d7579 to your computer and use it in GitHub Desktop.
Save fersandiP/ae4ca417f1091118767a8ea3dd8d7579 to your computer and use it in GitHub Desktop.
Script to delete tweets automatically from your browser
// Open your tweet pages (Tweets, Tweets & replies, or Media)
// Execute this script in the console
// Tested on Chrome Version 91.0.4472.114 (Official Build) (x86_64) MacOS
// If the script stopped, refresh the page and execute it again
var tweets = document.querySelectorAll('[data-testid="tweet"]');
while (tweets.length > 0) {
tweets.forEach(function(tweet){
// Check if there exist unretweet button
const unretweetButton = tweet.querySelectorAll(['[data-testid="unretweet"]'])
if (unretweetButton.length > 0) {
unretweetButton[0].click()
const unretweetButtonConfirm = document.querySelectorAll(['[data-testid="unretweetConfirm"]'])[0]
unretweetButtonConfirm.click()
} else {
// Click the caret button on the tweet
const caret = tweet.querySelectorAll(['[data-testid="caret"]'])[0];
caret.click();
// Click Delete Tweet button
const item = document.querySelectorAll('[role="menuitem"]')[0];
item.click();
// Click confirm delete tweet button
const confirmButton = document.querySelectorAll('[data-testid="confirmationSheetConfirm"]')[0];
confirmButton.click();
}
});
// Set the delay 3s to wait for incoming tweet
await new Promise(r => setTimeout(r, 3000));
tweets = document.querySelectorAll('[data-testid="tweet"]');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment