Created
September 2, 2023 00:07
-
-
Save dharFr/212f381bae0429dcd375c5cf9e6b3d1d to your computer and use it in GitHub Desktop.
Delete Tweets, RT & Likes from your Twitter/X account, from the browser console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment