Skip to content

Instantly share code, notes, and snippets.

@chriskirknielsen
Last active December 26, 2023 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskirknielsen/ead337bfaad936f1aacc048b90816216 to your computer and use it in GitHub Desktop.
Save chriskirknielsen/ead337bfaad936f1aacc048b90816216 to your computer and use it in GitHub Desktop.
Twitter Deleter
function untweet(username, mode = null) {
let currPost;
let currPostSeen;
let loop;
if (!mode) {
mode = (window.location.href.includes(`${username}/with_replies`)) ? 'replies' : 'posts';
}
function deleteMyTweet() {
currPost = null;
currPostSeen = 0;
loop = setInterval(() => {
let firstPost = null;
let repostButton = null;
if (mode === 'replies') {
firstPost = Array.from(document.querySelectorAll('[aria-label*="Timeline: "][aria-label*="’s posts"] > * > [data-testid="cellInnerDiv"]:not(:has(> div > div:empty)):not(:has([href*="/i/connect_people"])):not(:has(> * > * > [data-testid="UserCell"])):not(:has([role="heading"][aria-level="2"]))')).find(p => p.clientHeight > 2 && !!p.querySelector(`[data-testid="UserAvatar-Container-${username}"`));
if (!firstPost) {
window.scrollBy(0, document.documentElement.clientHeight);
return;
}
} else {
firstPost = Array.from(document.querySelectorAll('[aria-label*="Timeline: "][aria-label*="’s posts"] > * > [data-testid="cellInnerDiv"]:not(:has(> div > div:empty)):not(:has([href*="/i/connect_people"])):not(:has(> * > * > [data-testid="UserCell"])):not(:has([role="heading"][aria-level="2"]))')).find(p => p.clientHeight > 2);
repostButton = firstPost && firstPost.querySelector('[role="button"][aria-label*="Reposted"i]');
}
if (currPost !== firstPost) {
currPost = firstPost;
currPostSeen = 0;
} else {
clearInterval(loop);
console.log({ currPost, firstPost });
currPostSeen++;
if (currPostSeen < 5) {
setTimeout(deleteMyTweet, 1000);
}
}
if (repostButton) {
repostButton.click();
setTimeout(() => {
document.querySelector('[role="menuitem"][data-testid="unretweetConfirm"').click();
}, 1);
}
else {
firstPost.querySelector('path[d="M3 12c0-1.1.9-2 2-2s2 .9 2 2-.9 2-2 2-2-.9-2-2zm9 2c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm7 0c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"]').closest('svg').closest('div').click();
setTimeout(() => {
document.querySelector('[role="menuitem"] [style*="color: rgb(244, 33, 46)"]').click();
setTimeout(() => {
document.querySelector('[role="button"][data-testid="confirmationSheetConfirm"]').click();
}, 10);
}, 10);
}
}, 150);
}
deleteMyTweet();
}
untweet('ckirknielsen', 'replies');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment