Skip to content

Instantly share code, notes, and snippets.

@kcubero27
Created July 13, 2023 17:26
Show Gist options
  • Save kcubero27/9e67e28ff62c8b5ccd5edd9be9a2f553 to your computer and use it in GitHub Desktop.
Save kcubero27/9e67e28ff62c8b5ccd5edd9be9a2f553 to your computer and use it in GitHub Desktop.
Remove Tweets and ReTweets
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