Skip to content

Instantly share code, notes, and snippets.

@aymericbeaumet
Last active April 14, 2024 07:47
Show Gist options
  • Save aymericbeaumet/d1d6799a1b765c3c8bc0b675b1a1547d to your computer and use it in GitHub Desktop.
Save aymericbeaumet/d1d6799a1b765c3c8bc0b675b1a1547d to your computer and use it in GitHub Desktop.
[Recipe] Delete all your likes/favorites from Twitter

Ever wanted to delete all your likes/favorites from Twitter but only found broken/expensive tools? You are in the right place.

  1. Go to: https://twitter.com/{username}/likes
  2. Open the console and run the following JavaScript code:
setInterval(() => {
  for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
    d.click()
  }
  window.scrollTo(0, document.body.scrollHeight)
}, 1000)
@Alex39-bot
Copy link

How do I turn the code off???

@knedl1k
Copy link

knedl1k commented Jun 23, 2022

How do I turn the code off???

Just refresh the page, F5.

@WizardOfOoo
Copy link

I combined some of the above to make this:
Was slow, and didn't have much action on the screen, but it worked.
Chrome / Win 10

setInterval(() => {
for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
d.click()
}
window.scrollTo(0, window.pageYOffset+300)
}, 10000)

@dcole819
Copy link

dcole819 commented Aug 1, 2022

How do I remove the code??? My Twitter has been acting up since I did this I want it back to normal please help

@kyllian-vssr
Copy link

Working nice today.

@dcole819
Copy link

dcole819 commented Aug 3, 2022

It’s unliking things but it still shows up in my likes just without the heart…anyway to remove the code???

@partsp
Copy link

partsp commented Aug 10, 2022

still can't get it to work. it deletes the tweets but then they come back

@nonononono9
Copy link

Works for a bit and then stops, most likely because of the API but then everything it unfavorites comes back. Which 100% defeats the purpose of this.

@kyllian-vssr
Copy link

kyllian-vssr commented Aug 15, 2022

It’s unliking things but it still shows up in my likes just without the heart…anyway to remove the code???

@dcole819, CTRL+F5 or MAJ+F5 to stop the scripts correctly.

Sometime the API will block you for some minutes or hours if you have mass likes to "remove". 😁

still can't get it to work. it deletes the tweets but then they come back

@partsp same here, just got blocked by API because of too much tweet. retry later. ^^

@MBUMILA
Copy link

MBUMILA commented Sep 4, 2022

It worked! thanks

Copy link

ghost commented Sep 11, 2022

I'm not so good with Javascript - does anyone know how to modify this to unlike Tweets which contain a certain phrase?- eg only unlike Tweets containing the phrase 'boiled eggs'.

@dystorwell
Copy link

dystorwell commented Sep 26, 2022

hello there.
I don't know why but it doesn't work. here's a screenshot of the error.
it worked for a hundred of likes and then stopped.
keep in mind I don't know anything about java.
have a good day :)

Schermata 2022-09-26 alle 21 18 17

edit. worked, then all my likes came back, including the ones I unliked before using this...

@ChitranshuV
Copy link

ChitranshuV commented Oct 12, 2022

setInterval(() => { for (const d of document.querySelectorAll('div[data-testid="unlike"]')) { d.click() } window.scrollTo(0, document.body.scrollHeight) }, 10000)

setInterval 5000 did not work on me. If you have more than 2000 likes, like me. Try 10000 for setInterval, it worked.

Anyway, thanks!

Working for me as of 12th Oct 2022. The only issue is that it starts throwing errors like api/graphql after some time. I take 5 mins break and restart it and it works great. There is rate limit of 900 requests every 15 minutes. https://developer.twitter.com/en/docs/twitter-api/rate-limits

Is there any code similarly for deleting tweets&repllies ??

@Kirytah
Copy link

Kirytah commented Oct 16, 2022

I haven't found any. If you find one please let me know.

@mscdo
Copy link

mscdo commented Nov 11, 2022

It worked for a moment, but as others said, the tweets come back. Still finding an answer to that.

@WizardOfOoo
Copy link

setInterval(() => { for (const d of document.querySelectorAll('div[data-testid="unlike"]')) { d.click() } window.scrollTo(0, document.body.scrollHeight) }, 10000)
setInterval 5000 did not work on me. If you have more than 2000 likes, like me. Try 10000 for setInterval, it worked.
Anyway, thanks!

Working for me as of 12th Oct 2022. The only issue is that it starts throwing errors like api/graphql after some time. I take 5 mins break and restart it and it works great. There is rate limit of 900 requests every 15 minutes. https://developer.twitter.com/en/docs/twitter-api/rate-limits

Is there any code similarly for deleting tweets&repllies ??

https://tweetdelete.net/

@lionbytes
Copy link

lionbytes commented Nov 13, 2022

setInterval(() => { for (const d of document.querySelectorAll('div[data-testid="unlike"]')) { d.click() } window.scrollTo(0, document.body.scrollHeight) }, 10000)
setInterval 5000 did not work on me. If you have more than 2000 likes, like me. Try 10000 for setInterval, it worked.
Anyway, thanks!

Working for me as of 12th Oct 2022. The only issue is that it starts throwing errors like api/graphql after some time. I take 5 mins break and restart it and it works great. There is rate limit of 900 requests every 15 minutes. https://developer.twitter.com/en/docs/twitter-api/rate-limits

Is there any code similarly for deleting tweets&repllies ??

I modified the code a while ago. It worked for me, you just need to run it and go do something while it deletes the tweets:
https://gist.github.com/lionbytes/2e8ad01d0ec318354aa5e95b746c7e54

@osmanbowser
Copy link

Works on Chrome! Thanks!

@chriiisclm
Copy link

chriiisclm commented Nov 18, 2022

nice still works on chrome, tab should be open tho.

@qoqnus13
Copy link

Hi,
How can I limit this code to a time period or a username? I don't want all likes to be removed and only want to remove the likes of a particular account

@dafunks
Copy link

dafunks commented Nov 28, 2022

Just so you all know, if you use GreaseMonkey you can easily do this with a script:
https://stackoverflow.com/questions/64863099/deleting-tweets-with-js-console/71333246#71333246 and it works really well.

@abdessalaam
Copy link

abdessalaam commented Dec 15, 2022

Would anyone please share the latest snippet? (15 Dec 2022 doesn't seem to be deleting likes...) - Thank you!
EDIT (18/12/22): The script might actually be working: it removes the "hearts" but the liked tweets still stay in place, so I was a bit confused.

@briocon7
Copy link

I have 13 likes on my account that i can't get rid of. I also can't see them. I assume these likes are from suspended twitter accounts. But i don't know for sure. I tried running the code but it didn't change anything. Any idea how to get rid of those invisible likes?

@plambrechtsen
Copy link

FYI for anyone who happens across this gist, there is a limit of 1000 likes / unlikes per day and older liked tweets don't show up as "liked" on your timeline, so you need to like and unlike them to actually remove them.
I am using semiphemeral to remove the likes and retweets.
As per https://github.com/micahflee/semiphemeral#deleting-old-likes

@bobmagicii
Copy link

bobmagicii commented Dec 30, 2022

the OG post is still working for me on the 30th of dec 2022. doing it in batches of 900 due to the rate limit.

i think a lot of people seeing it not work are seeing cache. the current iteration of their site uses stupid amounts of local cache in addition to server side stuff. a hard refresh (shift+refresh) usually clears it. also deleting my tweets with another script, my counter still says 41 even though there are 1. and yesterday it still said 83. so that was more of their server side cache i think and maybe a week from now it'll be a different lower number.

also i think if you posted in "communities" those count as posts but are not searchable by anything on their system. i was semi active in the php community and there seems to be no way to even manually find those posts to hand delete.

if you're rooting around the dev console to use this you can kinda see how absolutely bad their app is. cors violations for days lmao.

another final note if you do hit the api rate limit, and hit it too hard, the rest of the ui will take a dump. if you hit the like delete rate limit and refresh there is a chance it will say you still have 300 likes, but "you dont have any likes yet" for a while, because the api just so angry. that only happened once so far though. it can also happen if you've blocked accounts. you'll have to unblock and unmute them.

@7jmoran
Copy link

7jmoran commented Jan 5, 2023

Screen Shot 2023-01-04 at 10 55 00 PM

Hello!

I hope those who see this are having a great week. I used the script to mass delete likes, and it was working well until it broke. I guess I did it too quickly and reached the limit. If anyone, absolutely anyone, can help me figure out how to fix this so that my likes will reappear so that I can continue deleting likes (carefully this time), I will be eternally grateful. Please. I am desperate. I am afraid that I have ruined Twitter forever. As you can see, it says that I have not liked anything yet, but I have over 5K likes.

Thank you!

@Jsdfngjkds
Copy link

i have the same problem, the no. of tweets is 300 but it says on the likes tab You don’t have any likes yet
. ANY HELP?

@bobmagicii
Copy link

bobmagicii commented Jan 8, 2023

every weekend i have to go back to twitter and more likes are there. its almost like it takes their system forever to dig them out of super old archive. and if i unlike like 20 of them, while still staring at more and refresh all of them will vanish. until next weekend again. im down to 291 now.

you just have to keep on keeping on.

@10ensura
Copy link

10ensura commented Jan 18, 2023

by favorite, you mean bookmarks yes or no ? thats can be usefull for myself if yes.

@jbreckmckye
Copy link

It's hard to say what the deal is with Twitter right now. Since the takeover it seems increasingly unstable. A lot of non-core things are apparently silently broken

@gomexreal
Copy link

thankyou sir :) worked your all script ,

@allbombs
Copy link

Thanks for sharing this.
It removed 5k likes, but now i'm stuck at 4k? It appears around 2018 is when the above script stopped working.

It's been 36 hours and stuck

@RodLeyton
Copy link

RodLeyton commented Feb 2, 2023

Working very well. Thank you, glad I searched first!
Takes a while, set interval a lot longer to stop twitters rate limiter.
Even 10sec still hit the rate limiter, but this was a new account so only had 10k likes.
Take note of the "[HTTP/2 429 Too Many Requests 208ms]".
If you want to run it overnight, may need to add delay per click instead.
Thank you very much

@rafacampoamor
Copy link

Is there a way to the same with Retweets?

@MohdAsad5
Copy link

My dear sir, I disliked all my posts on Twitter at once through the code you mentioned. And I became very happy. But I want to ask you that can we delete or undo all tweets or retweets on Twitter in one go through code..??
Let me know if you have any such code. I want to delete and undo all tweets of twitter through code.
If you have any such code please send me code on E-mail: mohdasad3786@gmail.com so that I can delete all tweets.
I am waiting for your reply. of your answer..!!

Regards
Mohd Asad

@subsubsubsubsubsub
Copy link

subsubsubsubsubsub commented Feb 25, 2023

is there a new code to remove likes? The above doesn't work for me anymore. deleted 2000 likes. 1000 left?

@subsubsubsubsubsub
Copy link

is there a new code to remove likes? The above doesn't work for me anymore. deleted 2000 likes. 1000 left?

try using this use the refresh and ctrl+L to clear the console and start this code

const run = () => { let intervalId = setInterval(() => { for (const d of document.querySelectorAll('div[data-testid="unlike"]')) { d.click(); } }, 3000);

let scrollIntervalId = setInterval(() => { window.scrollTo(0, document.body.scrollHeight); }, 5000);

setTimeout(() => { clearInterval(intervalId); clearInterval(scrollIntervalId); setTimeout(run, 900000); }, 900000); };

run();

net::ERR_BLOCKED_BY_ADBLOCKER

@subsubsubsubsubsub
Copy link

such a problem, in the likes, there are no likes on the posts themselves. it is necessary to like and remove, maybe because of this the script does not work? and need to be redone? likes for 2018

@jbreckmckye
Copy link

jbreckmckye commented Feb 25, 2023

I am aware that this is turning into the programmer's version of playing Stairway to Heaven.

But here's mine

  • rather than estimating a scroll offset, it simply uses focus() to scroll the next item into view
  • has a backoff every 50 unlikes to prevent HTTP 429: Too Many Requests
function nextUnlike() {
  return document.querySelector('[data-testid="unlike"]')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next && count < 500) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  console.log('Out of unlikes, count =', count)
}

removeAll() 

At time of writing this is printing Unliked 1506 tweets

@subsubsubsubsubsub
Copy link

Doesn't work again. a day has passed.

@isabellechia427
Copy link

isabellechia427 commented Feb 27, 2023

image

hi! may i know is there anyway to fix this? i've tried the code above but it became like this. very thankful if anybody can help me to solve this problem :( thanks a lot!

@rogervenson
Copy link

image

hi! may i know is there anyway to fix this? i've tried the code above but it became like this. very thankful if anybody can help me to solve this problem :( thanks a lot!

hey, were you able to fix this somehow?? I'm so annoyed by it, and the worst thing is that other accounts can see these likes that are invisible for me...

@bitridge
Copy link

bitridge commented Mar 6, 2023

This is amazing

@isabellechia427
Copy link

image
hi! may i know is there anyway to fix this? i've tried the code above but it became like this. very thankful if anybody can help me to solve this problem :( thanks a lot!

hey, were you able to fix this somehow?? I'm so annoyed by it, and the worst thing is that other accounts can see these likes that are invisible for me..

noooo, my Twitter is still like this :( but not sure can other accs see the likes

@razaahmed301
Copy link

It worked for me! Thanks

@10ensura
Copy link

10ensura commented Mar 9, 2023

Pour votre information, pour tous ceux qui traversent cet essentiel, il y a une limite de 1000 likes / likes par jour et les anciens tweets aimés n'apparaissent pas comme "aimés" sur votre chronologie, vous devez donc les aimer et ne pas les aimer pour les supprimer. J'utilise semiphemeral pour supprimer les likes et les retweets. Selon https://github.com/micahflee/semiphemeral#deleting-old-likes

isn't work...

@ranjanquiet
Copy link

none of the code on this page are working.

@verma-rajatk
Copy link

Great job! It works as of Mar 17 2023. Many Thanks.

@ianathompson
Copy link

I am aware that this is turning into the programmer's version of playing Stairway to Heaven.

But here's mine

  • rather than estimating a scroll offset, it simply uses focus() to scroll the next item into view
  • has a backoff every 50 unlikes to prevent HTTP 429: Too Many Requests
function nextUnlike() {
  return document.querySelector('[data-testid="unlike"]')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  console.log('Out of unlikes, count =', count)
}

removeAll() 

At time of writing this is printing Unliked 1506 tweets

This works wonderfully. Thank you @jbreckmckye

@limeraiin
Copy link

I am aware that this is turning into the programmer's version of playing Stairway to Heaven.
But here's mine

  • rather than estimating a scroll offset, it simply uses focus() to scroll the next item into view
  • has a backoff every 50 unlikes to prevent HTTP 429: Too Many Requests
function nextUnlike() {
  return document.querySelector('[data-testid="unlike"]')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  console.log('Out of unlikes, count =', count)
}

removeAll() 

At time of writing this is printing Unliked 1506 tweets

This works wonderfully. Thank you @jbreckmckye

It is not working either

main.2b1c61fa.js:1 POST https://twitter.com/i/api/graphql/ZYKSe-w7KEslx3JhSIk5LA/UnfavoriteTweet 429

it logs "x tweets removed" but in reality nothing changes.

@jbreckmckye
Copy link

jbreckmckye commented Apr 2, 2023

@limeraiin You may need to increase the timeout. Wait a day or so as well, so you aren't on any LB blacklists.

I think sometimes it takes a little while for the API to fully reconcile updates.

It's also possible twitter are clamping down further on rate issues due to problems on their platform. It's a bit inexact.

@danielraffel
Copy link

Any idea how to unretweet a tweet If you’re blocked? I read this...
https://medium.com/@SeloSlav/how-to-unretweet-a-tweet-if-youre-blocked-9b4c294f4b3f
And have the tweetID...possible to modify one of the above scripts and use the ID and unretweet it in the console?

@nicoh88
Copy link

nicoh88 commented Apr 18, 2023

Hello, can the script be tapped so that only likes older than 30 days are removed? Would be great!

And maybe the whole thing for retweets too?

Thanks

@GitJuankof
Copy link

Funcionó hasta cierto punto, porque, al igual que otros, me apacen likes invisibles que no se dejaron borrar. ¡Muchas gracias!

@sunnycs121
Copy link

sunnycs121 commented May 17, 2023

I thought it was working until i refreshed the likes page, all likes were there and now I cannot even unlike manually. I f i try to manually unlike any post it automatically likes it again. Long story short now my likes are permanent forever. 👎

@asontemn
Copy link

Thanks!

@paul3xl
Copy link

paul3xl commented Jun 9, 2023

I thought it was working until i refreshed the likes page, all likes were there and now I cannot even unlike manually. I f i try to manually unlike any post it automatically likes it again. Long story short now my likes are permanent forever. 👎

same :(

@bfontaine
Copy link

bfontaine commented Jul 29, 2023

I thought it was working until i refreshed the likes page, all likes were there and now I cannot even unlike manually. I f i try to manually unlike any post it automatically likes it again. Long story short now my likes are permanent forever. 👎

I have the same issue, but it’s only temporary: it’s because with all these calls you hit the API limits, and you can’t call it anymore for a while. Come back ten minutes later, and you should be able to delete likes again.

@inakicalvo
Copy link

Thanks a lot! This helped me a lot!

@rhodiumtertbutyl
Copy link

Okay, so here is my experience with this. I used it about a week or so ago, and my likes were still there but they did not have the red heart on them. This morning, however, all of my likes were deleted and I only have a handful or so. It takes a bit of time for the API to catch up I think, especially if you have a lot. I had the same issues as people above, although, mine did show up for me. Just could not manually unlike them. Thanks for providing this code, really appreciate it. Sites like tweetdeleter and semiephemeral did not work for likes.

@rhodiumtertbutyl
Copy link

Alright, just kidding. I went back to my original like count with the red hearts blurred out again. Interested to see why it reverted back.

@rhodiumtertbutyl
Copy link

Alright, just kidding. I went back to my original like count with the red hearts blurred out again. Interested to see why it reverted back.

OKAY here is an update: after about a month or so, my likes appeared to go back to normal and I could manually unlike them. HOWEVER, I don't think the code ended up deleting any of them. So if you plan to utilize this, make sure there's a way to only unlike a certain amount that does not fuck with the API. I don't know how to do it but someone in here might.

@chrisheninger
Copy link

image

Checking the network request's response shows rate-limit info.

If you're running the command you'll quickly find out you can only unlike ~500 tweets in a ~15 minute period (as of September 2023)

You'll need to wait for the limit to reset– you can copy/paste the timestamp into https://www.epochconverter.com/ to figure out when it will reset.

@jbreckmckye
Copy link

jbreckmckye commented Sep 18, 2023

Good find @chrisheninger! I guess then any script should take that into account

function nextUnlike() {
  return document.querySelector('[data-testid="unlike"]')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next && count < 500) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  if (next) {
    console.log('Finished early to prevent rate-limiting')
  } else {
    console.log('Finished, count =', count)
  }
}

removeAll() 

@Eggroley
Copy link

Eggroley commented Nov 3, 2023

Anyone have something that works for the old twitter layout? I currently can't see any past likes at all using the new twitter layout. Old one still shows them. Right now I'm using an extension to get the old look.

@keerthiteja
Copy link

Anyone have something that works for the old twitter layout? I currently can't see any past likes at all using the new twitter layout. Old one still shows them. Right now I'm using an extension to get the old look.

If you are using dimdenGD extension, you can use the below updated code. I just updated the querySelector .

function nextUnlike() {
  return document.querySelector('.tweet-interact-favorite.tweet-interact-favorited')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next && count < 500) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  if (next) {
    console.log('Finished early to prevent rate-limiting')
  } else {
    console.log('Finished, count =', count)
  }
}

removeAll()

@Eggroley
Copy link

Anyone have something that works for the old twitter layout? I currently can't see any past likes at all using the new twitter layout. Old one still shows them. Right now I'm using an extension to get the old look.

If you are using dimdenGD extension, you can use the below updated code. I just updated the querySelector .

function nextUnlike() {
  return document.querySelector('.tweet-interact-favorite.tweet-interact-favorited')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next && count < 500) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  if (next) {
    console.log('Finished early to prevent rate-limiting')
  } else {
    console.log('Finished, count =', count)
  }
}

removeAll()

Thanks! Works well

Unfortunately, now I'm at the point where posts don't even show likes. I have to like and unlike to remove them :/

Twitter is lame

@TheMambaDev
Copy link

Thank you @aymericbeaumet appreciate it

@schmutzie
Copy link

Anyone have something that works for the old twitter layout? I currently can't see any past likes at all using the new twitter layout. Old one still shows them. Right now I'm using an extension to get the old look.

If you are using dimdenGD extension, you can use the below updated code. I just updated the querySelector .

function nextUnlike() {
  return document.querySelector('.tweet-interact-favorite.tweet-interact-favorited')
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function removeAll() {
  let count = 0
  let next = nextUnlike()
  while (next && count < 500) {
    next.focus()
    next.click()
    console.log(`Unliked ${++count} tweets`)
    await wait(count % 50 === 0 ? 30000 : 2000)
    next = nextUnlike()
  }
  if (next) {
    console.log('Finished early to prevent rate-limiting')
  } else {
    console.log('Finished, count =', count)
  }
}

removeAll()

Is there a way to have this first like, and then unlike tweets on the Likes page? The first script here left me with over 121K formerly liked tweets still counted and sitting under the Likes section. Only liking again and then unliking again fully removes them.

@trinlol
Copy link

trinlol commented Jan 1, 2024

Here is a version for likes, but you can specify tweets from a specific user to delete.

setInterval(() => {
  function removePostsByAuthor(authorHandle) {
    let posts = Array.from(document.querySelectorAll('.tweet'));
    posts.forEach(post => {
      let author = post.querySelector('.tweet-header-handle').textContent;
      if (author === authorHandle) {
        let likeButton = post.querySelector('.tweet-button.tweet-interact-favorite.tweet-interact-favorited');
        if (likeButton) {
          likeButton.click();
        }
      }
    });
  }

  // Call the function with the author's handle
  removePostsByAuthor('@USERNAME'); // Case sensitive (must match exactly)
  window.scrollTo(0, document.body.scrollHeight)
}, 1000)

Here is a version for retweets, but you can specify tweets from a specific user to delete.

setInterval(() => {
function removePostsByAuthor(authorHandle) {
  let posts = Array.from(document.querySelectorAll('.tweet'));
  posts.forEach(post => {
    let author = post.querySelector('.tweet-header-handle').textContent;
    if (author === authorHandle) {
      let tweetButton = post.querySelector('.tweet-button.tweet-interact-retweet.tweet-interact-retweeted');
      if (tweetButton) {
        tweetButton.click();
        let retweetMenu = tweetButton.parentElement.querySelector(".tweet-interact-retweet-menu-retweet");
        if (retweetMenu) {
          retweetMenu.click();
        }
      }
    }
  });
}

// Call the function with the author's handle
removePostsByAuthor('@USERNAME'); // Case sensitive (must match exactly)
  window.scrollTo(0, document.body.scrollHeight)
}, 1000)

Probably a better way to do this, but it works.

Must be using the old twitter extension as the above post's OldTwitter - Easier to get element IDs.

@danielwagn3r
Copy link

Made a little modification, which adds a page scroll to load futher likes in case you've got really many of them

function nextUnlike() {
  return document.querySelector('[data-testid="unlike"]');
}

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function removeAll() {
  let count = 0;
  let next = nextUnlike();
  while (next && count < 500) {
    try {
      next.focus();
      next.click();
      console.log(`Unliked ${++count} tweets`);
      await wait(count % 50 === 0 ? 60000 : 10000); // Increased wait times
      next = nextUnlike();
      if (!next && count < 500) {
        window.scrollTo(0, document.body.scrollHeight); // Scroll to the bottom of the page
        await wait(10000); // Increased wait time for more tweets to load
        next = nextUnlike(); // Get the next unlike button
      }
    } catch (error) {
      console.error('An error occurred:', error);
      break;
    }
  }
  if (next) {
    console.log('Finished early to prevent rate-limiting');
  } else {
    console.log('Finished, count =', count);
  }
}

removeAll();

@captainhook
Copy link

Is there a way to have this first like, and then unlike tweets on the Likes page? The first script here left me with over 121K formerly liked tweets still counted and sitting under the Likes section. Only liking again and then unliking again fully removes them.

I'm facing this issue now too. You could possibly run the script to first go and like a few hundred tweets and then after that a script to unlike them again. Or you'd have to create a counter around document.querySelector and loop through that.

@celine1OF1
Copy link

Screenshot 2024-01-10 091055
why arent the rest of my likes showing?

@captainhook
Copy link

Plenty of people above having the same issue with no definitive reasoning. Could be rate limiting, could be free tier limits, could be API bug, could be something else.

@h0jeZvgoxFepBQ2C
Copy link

This works fine for me:

setInterval(() => {
  const d = document.querySelector('div[data-testid="unlike"]')
  if(d) {
    d.click()
  } else {
    window.scrollTo(0, document.body.scrollHeight)
  }
}, 1000)

@Valx01P
Copy link

Valx01P commented Jan 29, 2024

Damn twitter API, these rate limits suck, how am I supposed to delete my socially incriminating twitter history if it only let's me remove 20 likes using a script before it stops letting me, twitter needs to implement an API endpoint to just remove all likes, tweets, retweets, etc. There is no way I'm gonna be able to remove thousands of likes manually lmao

@Fodules
Copy link

Fodules commented Feb 9, 2024

This works fine for me:

setInterval(() => {
  const d = document.querySelector('div[data-testid="unlike"]')
  if(d) {
    d.click()
  } else {
    window.scrollTo(0, document.body.scrollHeight)
  }
}, 1000)

works for me as well

@nikolaydubina
Copy link

this is incredible 👍

@nikolaydubina
Copy link

nikolaydubina commented Feb 17, 2024

I added more scripts for https://github.com/nikolaydubina/twitter-remover

  • removing tweets
  • removing retweets
  • removing replies
  • removing followers

@skibideetoilet
Copy link

is there one that likes and unlikes the tweets in your likes that for some reason are unliked but haven't been removed?

@schmutzie
Copy link

schmutzie commented Feb 22, 2024 via email

@LetyEspinosa19
Copy link

It does not work for me, I also tried this script:

setInterval(() => {
const d = document.querySelector('div[data-testid="unlike"]')
if(d) {
d.click()
} else {
window.scrollTo(0, document.body.scrollHeight)
}
}, 1000)

And didn't worked also ):

Copy link

ghost commented Mar 13, 2024

Is there anyone who deletes DMs chat?

@NewWestSon
Copy link

It didn't work for me, so I tried waiting 100 milliseconds and it seemed to work, odd.
setInterval(() => {
for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
d.click()
}
window.scrollTo(0, document.body.scrollHeight)
setTimeout(pass, 100);
}, 1000)

@Kafsu
Copy link

Kafsu commented Apr 4, 2024

function getAllTweetButtons() {
return Array.from(document.querySelectorAll('.tweet-interact-favorite'));
}

function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function processTweet(tweetButton) {
tweetButton.focus();
tweetButton.click(); // Click to like (if not liked) or unlike (if liked)
await wait(1000); // Reduced wait time

// Check if the tweet is still liked, if so, click again to unlike
if (tweetButton.classList.contains('tweet-interact-favorited')) {
tweetButton.click(); // Click again to ensure it's unliked
await wait(500); // Reduced wait time
console.log('Ensured tweet is unliked');
} else {
console.log('Processed tweet');
}
}

async function removeAll() {
let count = 0;
let tweetButtons = getAllTweetButtons();

while (count < 500 && tweetButtons.length > 0) {
for (let i = 0; i < tweetButtons.length && count < 500; i++) {
await processTweet(tweetButtons[i]);
count++;
if (count % 50 === 0) {
console.log('Waiting to prevent rate-limiting');
await wait(15000); // Wait to prevent rate-limiting
}
}

// Scroll to the bottom of the page to load more tweets
window.scrollTo(0, document.body.scrollHeight);
await wait(3000); // Wait for more tweets to load
tweetButtons = getAllTweetButtons(); // Refresh the list of tweet buttons

}

console.log('Finished, count =', count);
}

removeAll();


Fix for shadow likes on feed
Works with Old Twitter layouts
Modify the rate limiting waiting as neccessary

@Anon14j1
Copy link

Anon14j1 commented Apr 5, 2024

function getAllTweetButtons() { return Array.from(document.querySelectorAll('.tweet-interact-favorite')); }

function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }

async function processTweet(tweetButton) { tweetButton.focus(); tweetButton.click(); // Click to like (if not liked) or unlike (if liked) await wait(1000); // Reduced wait time

// Check if the tweet is still liked, if so, click again to unlike if (tweetButton.classList.contains('tweet-interact-favorited')) { tweetButton.click(); // Click again to ensure it's unliked await wait(500); // Reduced wait time console.log('Ensured tweet is unliked'); } else { console.log('Processed tweet'); } }

async function removeAll() { let count = 0; let tweetButtons = getAllTweetButtons();

while (count < 500 && tweetButtons.length > 0) { for (let i = 0; i < tweetButtons.length && count < 500; i++) { await processTweet(tweetButtons[i]); count++; if (count % 50 === 0) { console.log('Waiting to prevent rate-limiting'); await wait(15000); // Wait to prevent rate-limiting } }

// Scroll to the bottom of the page to load more tweets
window.scrollTo(0, document.body.scrollHeight);
await wait(3000); // Wait for more tweets to load
tweetButtons = getAllTweetButtons(); // Refresh the list of tweet buttons

}

console.log('Finished, count =', count); }

removeAll();

Fix for shadow likes on feed Works with Old Twitter layouts Modify the rate limiting waiting as neccessary

Im getting a Promise error when i try this
"promise {: undefined}"

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