Skip to content

Instantly share code, notes, and snippets.

@parkr
Last active December 5, 2024 00:45
Show Gist options
  • Select an option

  • Save parkr/d600696478d03d6f9c32 to your computer and use it in GitHub Desktop.

Select an option

Save parkr/d600696478d03d6f9c32 to your computer and use it in GitHub Desktop.
delete your tweets and un-retweet tweets
// go to https://twitter.com/your-username, and enter the following into the developer console:
for(var i = 1; i < 500; i++){ // just do it a bunch
// Un retweet
document.getElementsByClassName("ProfileTweet-actionButtonUndo")[i].click();
document.getElementsByClassName("js-close")[0].click();
// Delete tweets
document.getElementsByClassName("js-actionDelete")[i].childNodes[1].click();
document.getElementsByClassName("delete-action")[0].click()
}
@micahporter

Copy link
Copy Markdown

I'm new to this site, but can you explain to me how to use this code to delete all my tweets? I've authorized several apps but for some reason my account won't allow those apps to do their job (deleting my tweets)... i want to know how to use this code 'cause it seems like it could be my only option at this point... i know how to open up the "developer console" and the "inspect element" on the google chrome site. but when i try to copy this code and paste it, it says "UNCAUGHT REFERENCE ERROR:....". please let me know asap! thank you:)

@SkyroamCleggett

Copy link
Copy Markdown

This script works, but you have to do it a few times because Twitter probably has implemented some sort of limit. Not sure if there would be a way to space out the script so that it's not performing the actions so rapidly.

Twitter server for me. 403 response code per https://developer.twitter.com/en/docs/basics/response-codes

403 Forbidden The request is understood, but it has been refused or access is not allowed. An accompanying error message will explain why. This code is used when requests are being denied due to update limits . Other reasons for this status being returned are listed alongside the error codes in the table below.

@rmak78

rmak78 commented Aug 27, 2018

Copy link
Copy Markdown

// Remove Likes
$(".ProfileTweet-action--unfavorite").click();

@helloromero

Copy link
Copy Markdown

This no longer works...

@nabilazzh

Copy link
Copy Markdown

please if u find another code or whatever it is for un-retweet, un-like and delete all of the tweets. tell me, i do be really need it ASAP :""""(

@nabilazzh

Copy link
Copy Markdown

i make this account just for comment on your post, so please help me...

@krrskl

krrskl commented Apr 24, 2020

Copy link
Copy Markdown

@Throwaway-MM

Copy link
Copy Markdown

This doesn't work anymore, I made a new one that works with the current more involved REACT UI:

https://gist.github.com/FocusWho/5a8e74895293eae0071cec612477c72f

@antlionguard

Copy link
Copy Markdown

@itsMaz1n

itsMaz1n commented Mar 3, 2022

Copy link
Copy Markdown

@c0c41n3

c0c41n3 commented Jun 13, 2022

Copy link
Copy Markdown

// Un retweet

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
for(var i = 1; i < 500; i++){
document.querySelectorAll('[data-testid="unretweet"]')[0].click()
await sleep(1000)
document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click()
await sleep(1000)
}

@thesarfo

thesarfo commented Feb 7, 2023

Copy link
Copy Markdown

// Un retweet

function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } for(var i = 1; i < 500; i++){ document.querySelectorAll('[data-testid="unretweet"]')[0].click() await sleep(1000) document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click() await sleep(1000) }

Does this still work? How do I use it?

@Golgrax

Golgrax commented Feb 12, 2023

Copy link
Copy Markdown

// Un retweet
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } for(var i = 1; i < 500; i++){ document.querySelectorAll('[data-testid="unretweet"]')[0].click() await sleep(1000) document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click() await sleep(1000) }

Does this still work? How do I use it?

yes it is.

@EndlessPossibility

Copy link
Copy Markdown

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
for(var i = 1; i < 500; i++){
document.querySelectorAll('[data-testid="unretweet"]')[0].click()
await sleep(1000)
document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click()
await sleep(1000)
}

// Un retweet

function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } for(var i = 1; i < 500; i++){ document.querySelectorAll('[data-testid="unretweet"]')[0].click() await sleep(1000) document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click() await sleep(1000) }

tysm !!

@nuke-web3

Copy link
Copy Markdown

This was needed for Firefox for me, 100ms :

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function unretweet() {
    for(var i = 1; i < 500; i++){
    document.querySelectorAll('[data-testid="unretweet"]')[0].click()
    await sleep(100)
    document.querySelectorAll('[data-testid="unretweetConfirm"]')[0].click()
    await sleep(100)
  }
}

unretweet()

@urstrulyrocky

Copy link
Copy Markdown

bro i got 1563:5 Uncaught TypeError: Cannot read properties of undefined (reading 'click')
at :5:58
( like this what to do not working in chrome

@urstrulyrocky

Copy link
Copy Markdown

is this code works in fire fox for sure ?

@azerwtv

azerwtv commented Aug 23, 2023

Copy link
Copy Markdown

This is the code I have used today and it works perfectly fine:

(function () {
    var delTweets = function () {
        var tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1].textContent;
        console.log('Remaining: ', tweetsRemaining);
        window.scrollBy(0, 10000);
        document.querySelectorAll('[aria-label="More"]').forEach(function (v, i, a) {
            v.click();
            document.querySelectorAll('span').forEach(function (v2, i2, a2) {
                if (v2.textContent === 'Delete') {
                    v2.click();
                    document.querySelectorAll('[data-testid="confirmationSheetConfirm"]').forEach(function (v3, i3, a3) {
                        v3.click();
                    });
                }
                else {
                    document.body.click();
                }
            });
        });
        setTimeout(delTweets, 0);
    };

    delTweets();
})();

Credits to: g-h-0-S-t for providing the code.

@hexcowboy

Copy link
Copy Markdown

^ modified the previous code to also "undo retweets"

(function () {
  var delTweets = function () {
    var tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1]
      .textContent;
    console.log("Remaining: ", tweetsRemaining);
    window.scrollBy(0, 10000);
    document
      .querySelectorAll('[aria-label="More"]')
      .forEach(function (v, _, _) {
        v.click();
        document.querySelectorAll("span").forEach(function (v2, i2, a2) {
          if (v2.textContent === "Delete") {
            v2.click();
            document
              .querySelectorAll('[data-testid="confirmationSheetConfirm"]')
              .forEach(function (v3, i3, a3) {
                v3.click();
              });
          } else {
            document.body.click();
          }
        });
      });
    document
      .querySelectorAll('[data-testid="unretweet"]')
      .forEach(function (v, _, _) {
        v.click();
        document
          .querySelectorAll('[data-testid="unretweetConfirm"]')
          .forEach(function (v2, _, _) {
            v2.click();
          });
      });
    setTimeout(delTweets, 0);
  };

  delTweets();
})();

you may need to refresh the page and restart the script every so often since it seems twitter rate limits loading tweets

@thesarfo

Copy link
Copy Markdown

I used this script and it worked for a while, but now my twitter likes are invisible. They do not show in my likes tab. What could be the problem, and how do I fix it?

@wesamlibya

Copy link
Copy Markdown

I have used this script and it has been working for a while, do you have any of yours working for it?

@M-YasirGhaffar

Copy link
Copy Markdown

^ modified the previous code to also "undo retweets"

(function () {
  var delTweets = function () {
    var tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1]
      .textContent;
    console.log("Remaining: ", tweetsRemaining);
    window.scrollBy(0, 10000);
    document
      .querySelectorAll('[aria-label="More"]')
      .forEach(function (v, _, _) {
        v.click();
        document.querySelectorAll("span").forEach(function (v2, i2, a2) {
          if (v2.textContent === "Delete") {
            v2.click();
            document
              .querySelectorAll('[data-testid="confirmationSheetConfirm"]')
              .forEach(function (v3, i3, a3) {
                v3.click();
              });
          } else {
            document.body.click();
          }
        });
      });
    document
      .querySelectorAll('[data-testid="unretweet"]')
      .forEach(function (v, _, _) {
        v.click();
        document
          .querySelectorAll('[data-testid="unretweetConfirm"]')
          .forEach(function (v2, _, _) {
            v2.click();
          });
      });
    setTimeout(delTweets, 0);
  };

  delTweets();
})();

you may need to refresh the page and restart the script every so often since it seems twitter rate limits loading tweets

now longer work for likes

@thesarfo

Copy link
Copy Markdown

I used this script over a year ago and now my twitter likes do not show in the likes tab. How do i fix this ?

@ferreira710

ferreira710 commented Jun 27, 2024

Copy link
Copy Markdown

setting a timeout to prevent browser to crash

(function () {
  var delTweets = function () {
    var tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1]
      .textContent;
    console.log("Remaining: ", tweetsRemaining);

    var moreButtons = document.querySelectorAll('[aria-label="More"]');
    var deleteCount = 0;

    moreButtons.forEach(function (v) {
      v.click();
      var deleteButtons = document.querySelectorAll("span");
      for (var i = 0; i < deleteButtons.length; i++) {
        if (deleteButtons[i].textContent === "Delete") {
          deleteButtons[i].click();
          document
            .querySelectorAll('[data-testid="confirmationSheetConfirm"]')
            .forEach(function (v3) {
              v3.click();
              deleteCount++;
            });
          break;
        }
      }
      document.body.click();
    });

    var unretweetButtons = document.querySelectorAll('[data-testid="unretweet"]');
    unretweetButtons.forEach(function (v) {
      v.click();
      document
        .querySelectorAll('[data-testid="unretweetConfirm"]')
        .forEach(function (v2) {
          v2.click();
        });
    });

    if (deleteCount === 0) {
      window.scrollBy(0, 1000);
    }

    setTimeout(delTweets, 2000);
  };

  delTweets();
})();

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