Created
July 13, 2023 17:26
-
-
Save kcubero27/9e67e28ff62c8b5ccd5edd9be9a2f553 to your computer and use it in GitHub Desktop.
Remove Tweets and ReTweets
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
const scrollToBottom = () => { | |
window.scrollTo({ top: document.body.scrollHeight }); | |
}; | |
const sleep = (ms) => { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
}; | |
const obtainTweets = () => { | |
return document.querySelectorAll("[data-testid='tweet']"); | |
}; | |
const removeTweets = async (tweets) => { | |
console.log('tweets!!', tweets); | |
for (const tweet of tweets) { | |
const isRetweet = tweet.querySelector("[data-testid='socialContext']"); | |
// UNRETWEET | |
if (isRetweet) { | |
const unRetweetButton = tweet.querySelector("[data-testid='unretweet']"); | |
unRetweetButton.click(); | |
await sleep(300); | |
const unRetweetMenu = document.querySelector( | |
'[data-testid="unretweetConfirm"]', | |
); | |
unRetweetMenu.click(); | |
continue; | |
} | |
// NORMAL TWEET | |
const threeDotsButton = tweet.querySelector("[role='button']"); | |
threeDotsButton.click(); | |
await sleep(100); | |
const menuDropdown = document.querySelector('[role="menu"]'); | |
const spanElements = menuDropdown.querySelectorAll('span'); | |
const deleteButton = Array.prototype.filter.call( | |
spanElements, | |
(span) => span.innerText === 'Delete', | |
); | |
if (!deleteButton.length) { | |
console.log('TWEET DOES NOT HAVE'); | |
continue; | |
} | |
deleteButton[0].click(); | |
await sleep(100); | |
const confirmDeleteButton = document.querySelector( | |
"[data-testid='confirmationSheetConfirm']", | |
); | |
confirmDeleteButton.click(); | |
await sleep(100); | |
} | |
}; | |
const main = async () => { | |
await sleep(3_000); | |
const tweets = obtainTweets(); | |
if (!tweets.length) { | |
return; | |
} | |
await removeTweets(tweets); | |
scrollToBottom(); | |
await main(); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment