Last active
August 16, 2023 17:21
-
-
Save 7rebux/015dfc0cdca6b8e7172f99e7e80457f3 to your computer and use it in GitHub Desktop.
Unlike a specific amount of tweets in a specific timespan
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
// Example: | |
// await magic("2021-01-01T00:00:00.000Z", "2022-12-29T00:00:00.000Z", 100); | |
function nextTweet(current) { | |
return current.parentElement.parentElement.parentElement.nextElementSibling?.querySelector('[data-testid="tweet"]'); | |
} | |
function getUnlikeButton(tweetElement) { | |
return tweetElement.querySelector('[data-testid="unlike"]'); | |
} | |
function getTime(tweetElement) { | |
return tweetElement.querySelector('time'); | |
} | |
function wait(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function magic(minTime, maxTime, maxCount) { | |
window.scrollTo(0, 0); | |
await wait(1000); | |
let count = 0; | |
let tweet = document.querySelector('[data-testid="tweet"]'); | |
while (tweet) { | |
if (maxCount !== undefined && count === maxCount) | |
break; | |
const unlikeButton = getUnlikeButton(tweet); | |
const timeElement = getTime(tweet); | |
const dateTime = timeElement.dateTime; | |
timeElement.scrollIntoView(); | |
if (dateTime >= minTime && dateTime <= maxTime) { | |
unlikeButton.focus(); | |
unlikeButton.click(); | |
console.log(`Unliked tweet on ${timeElement.innerHTML}`); | |
count++; | |
await wait(1000); | |
} | |
tweet = nextTweet(tweet); | |
await wait(500); | |
} | |
console.log(`Finished! Unliked ${count} tweets`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment