Created
February 12, 2025 09:52
-
-
Save Explorare/5d88d965eb970a8bd74121453bee8298 to your computer and use it in GitHub Desktop.
Scroll down on timneline, focus and click the unlike and download buttons.
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
function nextUnlike() { | |
return document.querySelector('[data-testid="unlike"]'); | |
} | |
function nextDownload() { | |
return document.querySelector('[class="harvester stream"]'); | |
} | |
function wait(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function removeAll() { | |
let count = 0; | |
let next = nextUnlike(); | |
let download = nextDownload(); | |
let waitTime = 3000; // Start with a shorter wait time of 3 seconds | |
while (next && count < 50) { | |
try { | |
next.focus(); | |
next.click(); | |
if (download) { | |
download.focus(); | |
download.click(); | |
} | |
console.log(`Unliked ${++count} tweets`); | |
await wait(waitTime); // Initial wait time of 3 seconds | |
next = nextUnlike(); | |
download = nextDownload(); | |
// If no unlike button is found, scroll to load more | |
if (!next && count < 100) { | |
window.scrollTo(0, document.body.scrollHeight); | |
await wait(5000); // Shorter wait for loading more tweets | |
next = nextUnlike(); | |
download = nextDownload(); | |
} | |
} catch (error) { | |
console.error('An error occurred:', error); | |
waitTime = Math.min(waitTime * 2, 60000); // Exponentially increase wait time if an error occurs | |
console.log(`Rate limit hit? Increasing wait time to ${waitTime / 1000} seconds.`); | |
await wait(waitTime); // Wait before retrying | |
} | |
} | |
if (next) { | |
console.log('Finished early to prevent rate-limiting'); | |
} else { | |
console.log('Finished, count =', count); | |
} | |
} | |
removeAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment