Skip to content

Instantly share code, notes, and snippets.

@lindenb
Last active January 11, 2025 11:40
Show Gist options
  • Save lindenb/9da4f65c8b3686019b387fc7f990c87f to your computer and use it in GitHub Desktop.
Save lindenb/9da4f65c8b3686019b387fc7f990c87f to your computer and use it in GitHub Desktop.
Delete Tweets

I want to delete all my tweets without deleting my account.

This script deletes your tweets and repost from twitter without using the Twitter API, just by using the firefox javascript scratchpad.

Chage YOURNAME in the script below.

The script is quite slow but it works so far , I set some long timeout to let the DOM document to (re)load.

May be it could be much faster but I'm not a javascript guy.

function confirmDelete() {
var iter = document.evaluate("//span[text()='Delete' and @style='text-overflow: unset;']",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
console.log("confirm "+a);
setTimeout(function() {
a.click();
},2000);
break;
}
}
function moreDelete() {
console.log("moreDelete");
var iter = document.evaluate("//span[text()='Delete']",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
console.log("moreDel "+a);
a.click();
setTimeout(confirmDelete,1000);
break;
}
}
function undoRepost() {
console.log("unretweet");
var iter = document.evaluate("//span[text()='Undo repost']",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
console.log("undo report "+a);
setTimeout(function() {
a.click();
},2000);
break;
}
}
function removeArticles() {
var L=[];
var iter = document.evaluate("//article[not(.//span/text()='YOURNAME')]",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
L.push(a);
}
for(i in L) {
var a=L[i];
if(a!=null && a.parentNode!=null) a.parentNode.removeChild(a);
}
}
function collect() {
removeArticles();
console.log("colllect");
if(Math.random()<0.5) {
var iter = document.evaluate("//div[@aria-label='More' and @role='button']",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
console.log("post "+a);
a.click();
setTimeout(moreDelete,2000);
break;
}
}
else {
var iter = document.evaluate("//div[contains(@aria-label,'Reposted') and @role='button' and @data-testid='unretweet']",document,null,XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
for(;;) {
var a = iter.iterateNext();
if(a==null) break;
console.log("undoRepost "+a);
a.click();
setTimeout(undoRepost,2000);
break;
}
}
}
setInterval(collect, 10000);
@nafal9aadi
Copy link

@nafal9aadiمرحبًا، أخشى أن هذا البرنامج النصي أصبح قديمًا الآن. علاوة على ذلك، يكتشف تويتر أن التغريدات غير كافية وغير كافية لحذفها وحظر حسابك وأيامها.

There are currently no posts on my account and the likes are only there as a number, but after a long period of time a few of them appear, whether they are posts that I have previously reposted or posts that I have put a heart on and they are a few years before I created my account. Is there any solution to delete them all at once or to speed up their appearance at least?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment