Skip to content

Instantly share code, notes, and snippets.

@ramsey
Last active October 25, 2023 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramsey/d26cbb27e763f17bf32a6a476e86fa24 to your computer and use it in GitHub Desktop.
Save ramsey/d26cbb27e763f17bf32a6a476e86fa24 to your computer and use it in GitHub Desktop.
Remove all of your likes on twitter.com
// Remove all of your likes on twitter.com
// https://gist.github.com/ramsey/d26cbb27e763f17bf32a6a476e86fa24
//
// 1. Go to https://twitter.com/YOUR_USER_NAME/likes
// 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
// 3. Paste this into the Developer Console and run it
//
// If you start seeing error messages in the console with the code
// "429," this means Twitter is rate-limiting you. Stop the script
// (i.e., reload or close the browser tab), and try again later.
//
// Adapted from: Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)
// https://gist.github.com/JamieMason/7580315
//
// Last Updated: 25 Oct 2023
(() => {
const $unlikeButtons = '[data-testid="unlike"]';
const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight);
const retry = {
count: 0,
limit: 3,
};
const retryLimitReached = () => retry.count === retry.limit;
const addNewRetry = () => retry.count++;
const sleep = ({ seconds }) =>
new Promise((proceed) => {
console.log(`WAITING FOR ${seconds} SECONDS...`);
setTimeout(proceed, seconds * 1000);
});
const unlikeAll = async (unlikeButtons) => {
console.log(`UNLIKING ${unlikeButtons.length} TWEETS...`);
await Promise.all(
unlikeButtons.map(async (unlikeButton) => {
unlikeButton && unlikeButton.click();
await sleep({ seconds: 2 });
})
);
};
const nextBatch = async () => {
const unlikeButtons = Array.from(document.querySelectorAll($unlikeButtons));
const unlikeButtonsWereFound = unlikeButtons.length > 0;
if (unlikeButtonsWereFound) {
await unlikeAll(unlikeButtons);
scrollToTheBottom();
await sleep({ seconds: 2 });
return nextBatch();
} else {
addNewRetry();
}
if (retryLimitReached()) {
console.log(`NO LIKED TWEETS FOUND, SO I THINK WE'RE DONE`);
console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`);
} else {
scrollToTheBottom();
await sleep({ seconds: 2 });
return nextBatch();
}
};
nextBatch();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment