Skip to content

Instantly share code, notes, and snippets.

@dharFr
Created September 2, 2023 00:07
Show Gist options
  • Select an option

  • Save dharFr/212f381bae0429dcd375c5cf9e6b3d1d to your computer and use it in GitHub Desktop.

Select an option

Save dharFr/212f381bae0429dcd375c5cf9e6b3d1d to your computer and use it in GitHub Desktop.

Revisions

  1. dharFr created this gist Sep 2, 2023.
    19 changes: 19 additions & 0 deletions delete-likes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    /**
    * 1. Go to "Likes" section of your profile (e.g. https://twitter.com/<your_twix_handle>/likes)
    * 2. Open browser Console (Cmd + Option + I on Mac, F12 otherwise?)
    * 3. Copy/Paste the script and press enter to run it.
    *
    * At some point, depending on the number of items you need to process, you might see the following error in the console:
    * > "the server responded with a status of 429"
    * That's TwiX rate limiting. Reload the page, wait a few minutes/hours before trying again, and you should be fine.
    * Inspired from https://stackoverflow.com/a/72515907
    */
    function deleteLikes() {
    console.log(document.querySelectorAll('[role="heading"]+div')[1].textContent);
    window.scrollBy(0, 10000);

    document.querySelectorAll('[data-testid="unlike"]').forEach(item => item.click())

    setTimeout(deleteLikes, 4000); // less than 4000 might be rate limited or account suspended. increase timeout if any suspend or rate limit happens
    }
    deleteLikes()
    50 changes: 50 additions & 0 deletions delete-tweets-RT.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    /**
    * 1. Go to "Likes" section of your profile (e.g. https://twitter.com/<your_twix_handle>)
    * 2. Open browser Console (Cmd + Option + I on Mac, F12 otherwise?)
    * 3. Copy/Paste the script and press enter to run it.
    *
    * If your TwiX UI is not in French, make sure to update line 36
    * (Change "Supprimer" to the label of the "Delete" menu item in your own language)
    *
    * At some point, depending on the number of items you need to process, you might see the following error in the console:
    * > "the server responded with a status of 429"
    * That's TwiX rate limiting. Reload the page, wait a few minutes/hours before trying again, and you should be fine.
    * Inspired from https://stackoverflow.com/a/72515907
    */
    function deleteTweetsRT() {
    console.log(document.querySelectorAll('[role="heading"]+div')[1].textContent);
    window.scrollBy(0, 10000);

    // Delete Retweets
    document.querySelectorAll('[data-testid="unretweet"]').forEach((item) => {
    item.click()
    document.querySelector('[data-testid="unretweetConfirm"]').click()
    })

    // Delete Tweets
    document.querySelectorAll('[data-testid="caret"]').forEach((item, index) => {
    // I wanted to keep the last 3 tweets, so I added a minimum index.
    // Set the value to 0 to remove all of them
    const KEEP_LAST_N_TWEETS = 3
    if (index >= KEEP_LAST_N_TWEETS) {
    item.click()
    // Menu apparently takes some time to appear. Let's wait a couple of milliseconds before
    // searching for the menuitem
    setTimeout(() => {
    const deleteBtn = document.querySelector('[data-testid="Dropdown"] [role="menuitem"]')

    // My TwiX is in French. You might want to change "Supprimer" to your own language
    if (deleteBtn?.textContent === 'Supprimer') {
    deleteBtn.click()
    document.querySelector('[data-testid="confirmationSheetDialog"] [data-testid="confirmationSheetConfirm"]')?.click()
    }
    else {
    document.body.click();
    }
    }, 100)
    }
    })

    setTimeout(deleteTweetsRT, 4000); //less than 4000 might be rate limited or account suspended. increase timeout if any suspend or rate limit happens
    }
    deleteTweetsRT()