Skip to content

Instantly share code, notes, and snippets.

@LaruYan
Last active November 18, 2022 12:33
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 LaruYan/54d0ce23cd1e3081fe374ddc8ee1bc3b to your computer and use it in GitHub Desktop.
Save LaruYan/54d0ce23cd1e3081fe374ddc8ee1bc3b to your computer and use it in GitHub Desktop.
Tweet delete button clicker (delete tweet from your own tweets only)
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);
@LaruYan
Copy link
Author

LaruYan commented Aug 22, 2022

DESIGNED TO RUN THIS ON YOUR OWN SEARCH PAGE

Search term looks like

from:(your_twitter_username) include:nativeretweets

@LaruYan
Copy link
Author

LaruYan commented Aug 22, 2022

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 :)

@LaruYan
Copy link
Author

LaruYan commented Aug 23, 2022

fixed a selector error tweetEntry.queryselector is not a function

@LaruYan
Copy link
Author

LaruYan commented Aug 31, 2022

NOW THIS IS TESTED AND WORKS GOOD ON SEARCH YOUR TWEETS PAGE.
Thanks for waiting the script complete.

@LaruYan
Copy link
Author

LaruYan commented Nov 18, 2022

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