Skip to content

Instantly share code, notes, and snippets.

@aymericbeaumet
Last active November 28, 2023 11:31
Star You must be signed in to star a gist
Embed
What would you like to do?
[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)
@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()

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