Skip to content

Instantly share code, notes, and snippets.

@aymericbeaumet
Last active December 19, 2024 19:13
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)
@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.

@EndlessPossibility
Copy link

EndlessPossibility 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

@gomz404
Copy link

gomz404 commented Jan 23, 2023

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

@EndlessPossibility
Copy link

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

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