Last active
December 26, 2023 23:42
-
-
Save chriskirknielsen/ead337bfaad936f1aacc048b90816216 to your computer and use it in GitHub Desktop.
Twitter Deleter
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 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