Created
October 8, 2025 16:49
-
-
Save abhijithvijayan/602bdaa2cc00320728ea0593b71b218e to your computer and use it in GitHub Desktop.
unlike all tweets in bulk on twitter
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
| // Unlike all the liked tweets in bulk | |
| const run = async () => { | |
| const xpath = "//div[contains(text(),' Likes')]"; | |
| const likesCountElmt = document.evaluate( | |
| xpath, | |
| document, | |
| null, | |
| XPathResult.FIRST_ORDERED_NODE_TYPE, | |
| null | |
| ).singleNodeValue; | |
| if (!(likesCountElmt instanceof HTMLElement)) { | |
| console.log("Likes count element not found"); | |
| return; | |
| } | |
| const count = +likesCountElmt.innerText.replace(",", "").match(/\d+/g)?.[0] || 0; | |
| console.log(`Detected ${count} total likes`); | |
| if (count === 0) { | |
| console.log("No liked tweets found. Reloading page..."); | |
| window.location.reload(); | |
| return; | |
| } | |
| const MAX_SCROLL_RETRIES = 5; | |
| let scrollRetries = 0; | |
| while (true) { | |
| const elements = [...document.querySelectorAll(`[data-testid="unlike"]`)]; | |
| if (elements.length > 0) { | |
| console.log(`Unliking ${elements.length} tweets...`); | |
| for (const btn of elements) { | |
| btn.click(); | |
| console.log("Unliked one tweet"); | |
| await new Promise((resolve) => setTimeout(resolve, 150)); | |
| } | |
| scrollRetries = 0; | |
| } else { | |
| console.log("No unlike buttons found. Scrolling..."); | |
| window.scrollTo(0, 0); | |
| await new Promise((resolve) => setTimeout(resolve, 200)); | |
| window.scrollTo(0, document.body.scrollHeight); | |
| await new Promise((resolve) => setTimeout(resolve, 2000)); | |
| scrollRetries += 1; | |
| if (scrollRetries > MAX_SCROLL_RETRIES) { | |
| console.log("Reached max scroll retries — stopping."); | |
| break; | |
| } | |
| } | |
| } | |
| console.log("Finished unliking all visible tweets!"); | |
| }; | |
| run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment