Showing posts with label Twitter. Show all posts
Showing posts with label Twitter. Show all posts

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);
    }
  }
}

Monday, May 13, 2024

Twitter: collect all links to posts on a page

The following snippet executed in the Developer Console will help you collect all the links to individual posts on a profile. Once the script has been executed, all you'll need to do is to scroll down (or navigate from post to post using the "J" key).

window.links = new Set();

window._updateLinks = () => {
    Array.from(document.querySelectorAll('a > time'))
        .map(node => node.parentNode.href)
        .forEach(link => window.links.add(link));
}

window._handleScroll = () => {
    _updateLinks();
    console.log("Links collected:", window.links.size);
}

window.addEventListener('scroll', _handleScroll);

Once you're ready to collect the data, you can copy it to the clipboard using:

copy(Array.from(window.links).join("\n"));

This will copy the links to all the posts you've scrolled through, one link per line.
Useful e.g. when wanting to archive the content from a profile.

Wednesday, July 12, 2023

Clear Twitter "interests" list

Twitter subscribes you to a list of interests:

https://twitter.com/settings/your_twitter_data/twitter_interests

Some code to help you clear it:

const sleep = t => new Promise(r => setTimeout(r, t));

async function purge() {
  const nodes = document.querySelectorAll('input[type="checkbox"]:checked');

  let i = 0;
  for (const node of nodes) {
    document.title = `${++i} / ${nodes.length}`;
    console.log(new Date().toISOString(), i, node.closest('label').querySelector('span').textContent);
    node.click();
    await sleep(3_000);
  }
}
purge().catch(console.error);