Skip to content

Instantly share code, notes, and snippets.

@antlionguard
Last active September 6, 2023 15:35
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save antlionguard/a1be44823d552fe378660fcaa37b0736 to your computer and use it in GitHub Desktop.
Save antlionguard/a1be44823d552fe378660fcaa37b0736 to your computer and use it in GitHub Desktop.
With this script, you can remove all tweets you are tweeted on Twitter. Don't forget add your nickname to line 9. (The script begins 60 seconds after pasting the code.)
const timer = ms => new Promise(res => setTimeout(res, ms));
setInterval(async () =>
{
// Get all tweets
const allTweets = document.querySelectorAll('.css-1dbjc4n.r-18u37iz.r-1wbh5a2.r-13hce6t');
// Filter tweets
const filteredTweets = Array.prototype.slice.call(allTweets).filter(x => x.innerText === '@{YOUR_TWITTER_NICKNAME}'); // --> e.g. '@twitter'
for (const tweet of filteredTweets) {
tweet.scrollIntoView();
// Click three dot and open action menu
tweet.parentElement.parentElement.parentElement.parentElement.parentElement.querySelector('div[data-testid="caret"]').click();
await timer(250);
// Click delete button
document.querySelector('.r-9l7dzd.r-4qtqp9.r-yyyyoo.r-1q142lx.r-1xvli5t.r-1rq6c10.r-dnmrzs.r-bnwqim.r-1plcrui.r-lrvibr').parentElement.parentElement.click();
await timer(250);
// Click confirm button
document.querySelector('div[data-testid="confirmationSheetConfirm"]').click();
await timer(250);
}
await window.scrollTo(0, document.body.scrollHeight);
}, 60000);
@mochammadfawwaz
Copy link

Helo @antlionguard

your code is working for me, but sometimes the script runs an error because the delete button can't click.
I try with my code:

const timer = ms => new Promise(res => setTimeout(res, ms));

setInterval(async () =>
{
// Get all tweets
const allTweets = document.querySelectorAll('.css-1dbjc4n.r-18u37iz.r-1wbh5a2.r-13hce6t');

  // Filter tweets
  const filteredTweets =  Array.prototype.slice.call(allTweets).filter(x => x.innerText === '@beli3gratis2'); // --> e.g. '@twitter'

  for (const tweet of filteredTweets) {
        tweet.scrollIntoView();
        // Click three dot and open action menu
        tweet.parentElement.parentElement.parentElement.parentElement.parentElement.querySelector('div[data-testid="caret"]').click();
        await timer(150);

        // Click delete button
        document.querySelector('.css-1dbjc4n .r-1loqt21.r-18u37iz.r-1ny4l3l.r-ymttw5.r-1yzf0co.r-o7ynqc.r-6416eg.r-13qz1uu').click();
        await timer(250);
        
        // Click confirm delete button
        document.querySelector('.r-1awozwy.r-jwli3a.r-6koalj.r-18u37iz.r-16y2uox.r-37j5jr.r-a023e6.r-b88u0q.r-1777fci.r-rjixqe.r-bcqeeo.r-q4m81j.r-qvutc0').click();
        await timer(450);
  }
  await window.scrollTo(0, document.body.scrollHeight);

}, 1000);

And gotcha! it works mannnn~
Thank you for your repository!
I hope your day will be nicely

@jellicoe
Copy link

jellicoe commented Oct 7, 2022

filteredTweets keeps coming out with length 0

I've set my user name at line 9 correctly

and checked allTweets which is populated with elements

and can see my username in innerText - but noticed innerText with name + date in differing formats

hence
const filteredTweets = Array.prototype.slice.call(allTweets).filter(x => x.innerText === '@{YOUR_TWITTER_NICKNAME}');

always has 0 in filteredTweets

so changed to use baseURI

const filteredTweets = Array.prototype.slice.call(allTweets).filter(x => x.baseURI === 'https://twitter.com/{myname}');

and worked your script worked and deleted all tweets

I noticed innerText would include my twitter name and the date - but the format was different from tweet to tweet

some were {name}\n{date}

some were {name}.{date}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment