Monday, July 1, 2024

Twitter: remove all likes

 The following block will remove all your Twitter likes, if you are on your profile's /likes page:

{
  const sleep = t => new Promise(r => setTimeout(r, t));
  let i = 0;
  while (true) {
    const nodes = document.querySelectorAll('button[data-testid="unlike"]');
    if (nodes.length === 0) {
      console.log('NOOP');
      await sleep(2_000);
      if (++i === 10) {
        console.log('DONE');
        break;
      }
    } else {
      i = 0;
    }  
        
    let j = 0;
    for (const node of nodes) {
      console.log(`${++j} / ${nodes.length}`);
      node.scrollIntoView();
      node.click();
      await sleep(2_000);
    }
  }
}