Last active
November 18, 2022 12:33
-
-
Save LaruYan/54d0ce23cd1e3081fe374ddc8ee1bc3b to your computer and use it in GitHub Desktop.
Tweet delete button clicker (delete tweet from your own tweets only)
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
var deleteTweetsTimer = null; | |
var doDeleteTweetsFn = () => { | |
clearInterval(deleteTweetsTimer); | |
const tweetEntry = document.querySelector('article[data-testid="tweet"]'); | |
if (!!tweetEntry) { | |
const unretweetBtn = tweetEntry.querySelector('div[data-testid="unretweet"]'); | |
const moreBtn = tweetEntry.querySelector('div[data-testid="caret"]'); | |
if (!!unretweetBtn) { | |
// undo retweet | |
unretweetBtn.click(); | |
setTimeout(() => { | |
const undoretweetMenu = document.querySelector('div[data-testid="Dropdown"]'); | |
const undoretweetMenuItem = undoretweetMenu.querySelector('div[data-testid="unretweetConfirm"]'); | |
if (!undoretweetMenuItem) { | |
window.scrollTo({ | |
top: document.body.scrollHeight, | |
left: 0, | |
behavior: 'auto' | |
}); | |
setTimeout(() => { | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 32); | |
}, 32); | |
return; | |
} | |
undoretweetMenuItem.click(); | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 32); | |
}, 32); | |
} else { | |
// delete tweet | |
moreBtn.click(); | |
setTimeout(() => { | |
const moreMenu = document.querySelector('div[data-testid="Dropdown"]'); | |
let qtyMoreMenuItems = 0; | |
let moreMenuItems = null | |
if (!!moreMenu){ | |
moreMenuItems = moreMenu.querySelectorAll('div[role="menuitem"]'); | |
if (!!moreMenuItems) { | |
qtyMoreMenuItems = moreMenuItems.length; | |
} | |
} | |
if (qtyMoreMenuItems < 1) { | |
setTimeout(() => { | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 32); | |
}, 32); | |
return; | |
} | |
const deleteMenu = moreMenuItems.item(0); | |
deleteMenu.click(); | |
setTimeout(() => { | |
const deletePopup = document.querySelector('div[data-testid="confirmationSheetDialog"]'); | |
if (!!deletePopup) { | |
deletePopup.querySelector('div[data-testid="confirmationSheetConfirm"]').click(); | |
window.scrollTo({ | |
top: document.body.scrollHeight, | |
left: 0, | |
behavior: 'auto' | |
}); | |
} | |
setTimeout(() => { | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 32); | |
}, 32); | |
}, 32); | |
}, 32); | |
} | |
} else { | |
window.scrollTo({ | |
top: document.body.scrollHeight, | |
left: 0, | |
behavior: 'auto' | |
}); | |
setTimeout(() => { | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 32); | |
}, 32); | |
} | |
}; | |
deleteTweetsTimer = setInterval(doDeleteTweetsFn, 16); |
For faster processing, I recommend a rule for uBlock Origin. this prevents images on each tweet from loading
add this in "My Filters" Tab on uBlock Origin's settings page.
twitter.com##section > div figure
don't forget to remove this after done deleting tweets :)
fixed a selector error tweetEntry.queryselector is not a function
NOW THIS IS TESTED AND WORKS GOOD ON SEARCH YOUR TWEETS PAGE.
Thanks for waiting the script complete.
bug fixes including one resolves 'error console "moreMenu is null" then stops'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DESIGNED TO RUN THIS ON YOUR OWN SEARCH PAGE
Search term looks like