Last active
October 25, 2023 18:42
-
-
Save ramsey/d26cbb27e763f17bf32a6a476e86fa24 to your computer and use it in GitHub Desktop.
Remove all of your likes on twitter.com
This file contains 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
// 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