Automação · JavaScript · X (Twitter)Automation · JavaScript · X (Twitter)

Limpa o teu X de uma vez.Clean up your X in one go.

Pequenos scripts que colas na consola do browser para apagar os guardados, desfazer os reposts e deixar de seguir contas em massa. Sem instalar nada.Small scripts you paste into your browser console to delete bookmarks, undo reposts and unfollow accounts in bulk. Nothing to install.

  ConsolaConsole · x.com/i/bookmarks

FuncionalidadesFeatures

Três scripts, cada um para uma limpeza.Three scripts, one for each cleanup.

Como usarHow to use

Funciona em qualquer browser, em qualquer SO.Works in any browser, on any OS.

Abre a página certaOpen the right page

Cada script corre numa página do X. Está indicada em cada script, mais abaixo.Each script runs on a specific X page. It is listed with each script below.

Abre a consolaOpen the console

Carrega em F12 e vai ao separador Console.Press F12 and go to the Console tab.

Cola o scriptPaste the script

Copia o script todo, cola na consola e carrega em Enter. Se o browser não deixar colar, escreve allow pasting, carrega em Enter e cola outra vez.Copy the whole script, paste it into the console and press Enter. If the browser won't let you paste, type allow pasting, press Enter and paste again.

Espera pelo DoneWait for Done

Quando aparecer Done na consola, acabou. Para parar a meio, recarrega a página com F5.When Done shows up in the console, it's finished. To stop midway, reload the page with F5.

Atenção: estas ações não se desfazem.Warning: these actions can't be undone.

Scripts

Muda o LIMIT no topo se quiseres fazer menos de cada vez.Change the LIMIT at the top if you want to do fewer at a time.

RemoveBookmarks

Remove os itens guardados.
Corre em: x.com/i/bookmarks · LIMIT = quantos guardados apagar por execução (500)
Removes your bookmarks.
Runs on: x.com/i/bookmarks · LIMIT = how many bookmarks to delete per run (500)

// If your connection is bad, the script might stop early
(async () => {
  const LIMIT = 500; // how many bookmarks will be deleted
  const sleep = ms => new Promise(r => setTimeout(r, ms));
  let removed = 0;
  let idleRounds = 0;

  while (removed < LIMIT && idleRounds < 5) {
    const buttons = document.querySelectorAll('[data-testid="removeBookmark"]');

    if (buttons.length) {
      idleRounds = 0;
      for (const b of buttons) {
        if (removed >= LIMIT) break;
        b.click();
        removed++;
        await sleep(400); // 0.4s per deleted bookmark
      }
      console.log(`Removed: ${removed}`);
    } else {
      idleRounds++;
    }

    window.scrollTo(0, document.body.scrollHeight);
    await sleep(800);
  }

  console.log(`Done. Total removed: ${removed}`);
})();

UndoAllReposts

Desfaz os reposts. Primeiro desce até ao fim para carregar tudo e depois vai de baixo para cima. As citações ficam de fora, porque são publicações tuas.
Corre em: o teu perfil (x.com/o_teu_nome) · LIMIT = quantos reposts desfazer por execução (500)
Undoes your reposts. It first scrolls to the bottom to load everything, then works from the bottom up. Quotes are left alone, since they are your own posts.
Runs on: your profile (x.com/your_name) · LIMIT = how many reposts to undo per run (500)

// If your connection is bad, the script might stop early
(async () => {
  const LIMIT = 500; // how many reposts will be undone
  const sleep = ms => new Promise(r => setTimeout(r, ms));
  let removed = 0;

  // Phase 1: scroll down until the page stops growing (loads everything)
  let lastHeight = 0;
  let sameRounds = 0;
  while (sameRounds < 4) {
    window.scrollTo(0, document.body.scrollHeight);
    await sleep(1500);
    const h = document.body.scrollHeight;
    sameRounds = h === lastHeight ? sameRounds + 1 : 0;
    lastHeight = h;
  }
  console.log("Page fully loaded, starting to undo reposts...");

  // Phase 2: go from the bottom to the top, undoing what is visible
  while (removed < LIMIT) {
    const buttons = document.querySelectorAll('[data-testid="unretweet"]');

    for (const b of buttons) {
      if (removed >= LIMIT) break;
      b.click();
      await sleep(300); // wait for the confirm menu to open
      const confirm = document.querySelector('[data-testid="unretweetConfirm"]');
      if (confirm) {
        confirm.click();
        removed++;
      }
      await sleep(500); // 0.5s per undone repost
    }

    if (window.scrollY === 0) break; // reached the top
    window.scrollBy(0, -window.innerHeight * 0.7); // scroll up
    await sleep(800);
  }

  console.log(`Done. Total removed: ${removed}`);
})();

UnfollowAll

Deixa de seguir as contas que segues.
Corre em: x.com/o_teu_nome/following · LIMIT = quantas contas deixar de seguir por execução (1000)
Unfollows the accounts you follow.
Runs on: x.com/your_name/following · LIMIT = how many accounts to unfollow per run (1000)

// If your connection is bad, the script might stop early
(async () => {
  const LIMIT = 1000; // how many accounts will be unfollowed
  const sleep = ms => new Promise(r => setTimeout(r, ms));
  let removed = 0;
  let idleRounds = 0;

  while (removed < LIMIT && idleRounds < 5) {
    const buttons = document.querySelectorAll('[data-testid$="-unfollow"]');

    if (buttons.length) {
      idleRounds = 0;
      for (const b of buttons) {
        if (removed >= LIMIT) break;
        b.click();
        await sleep(150); // wait for the confirm popup to open
        const confirm = document.querySelector('[data-testid="confirmationSheetConfirm"]');
        if (confirm) {
          confirm.click();
          removed++;
        }
        await sleep(400); // 0.4s per unfollow
      }
      console.log(`Unfollowed: ${removed}`);
    } else {
      idleRounds++;
    }

    window.scrollTo(0, document.body.scrollHeight);
    await sleep(700);
  }

  console.log(`Done. Total unfollowed: ${removed}`);
})();

DúvidasFAQ

O que costuma aparecer.The usual questions.

O script parou a meioThe script stopped midway

Se a ligação estiver fraca, pode parar antes do fim. Corre outra vez.On a weak connection it can stop before the end. Just run it again.

Deixou de funcionar ao deixar de seguirIt stopped working while unfollowing

Se deixares de seguir muito depressa, o X pode bloquear-te por uns tempos. Espera um bocado e volta a correr, ou baixa o LIMIT e faz em lotes.If you unfollow too fast, X may block you for a while. Wait a bit and run it again, or lower the LIMIT and do it in batches.

Não faz nadaIt does nothing

Os scripts dependem da estrutura das páginas do X. Se o X mudar alguma coisa, podem deixar de funcionar.The scripts depend on how X's pages are built. If X changes something, they may stop working.

Funciona no telemóvel?Does it work on mobile?

Não, precisas da consola de um browser de computador.No, you need the console of a desktop browser.