Skip to content

Instantly share code, notes, and snippets.

@dustywusty
Last active September 3, 2023 07:33
Show Gist options
  • Save dustywusty/645d89f926b9cb47af8ed3dd839cccec to your computer and use it in GitHub Desktop.
Save dustywusty/645d89f926b9cb47af8ed3dd839cccec to your computer and use it in GitHub Desktop.
twitter unlike unlike-all script browser
// for your browser's javascript console on the <https://twitter.com/user/likes> page
let totalUnlikedCount = 0;
const clickUnlikeButtons = () => {
const unlikeButtons = Array.from(document.querySelectorAll('div[data-testid="unlike"]'));
let count = 0;
unlikeButtons.forEach((button) => {
const ariaLabel = button.getAttribute('aria-label');
const likesMatch = ariaLabel && ariaLabel.match(/^\d+\sLikes?\.\sLiked$/);
if (likesMatch) {
button.click();
count++;
}
});
return count;
};
const scrollToBottom = () => {
window.scrollTo(0, document.body.scrollHeight * 2);
};
const main = async () => {
while (true) {
if (totalUnlikedCount >= 499) {
console.log('Reached rate limit of 499, stopping!');
break;
}
const count = clickUnlikeButtons();
console.log(`Unliked ${count} tweets this round!`);
totalUnlikedCount += count;
scrollToBottom();
await new Promise(resolve => setTimeout(resolve, 10000));
}
console.log(`Total unliked tweets: ${totalUnlikedCount}`);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment