Created
September 14, 2023 06:18
-
-
Save afiestas/5956f688f8a57ee3a1181dd1c08eaf68 to your computer and use it in GitHub Desktop.
Delete all twitter content from an account
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
async function waitForElement(selector) { | |
return new Promise(resolve => { | |
const observer = new MutationObserver(mutations => { | |
mutations.forEach(mutation => { | |
Array.from(mutation.addedNodes).forEach(addedNode => { | |
const n = addedNode.querySelector(selector); | |
if (n) { | |
resolve(n); | |
observer.disconnect(); | |
} | |
}); | |
}); | |
}); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
}); | |
} | |
async function deleteTweet(ele) { | |
let p = waitForElement('div[data-testid="Dropdown"]'); | |
ele.click(); | |
const dd = await p; | |
const dBtn = Array.from(dd.querySelectorAll('*')).find(el => el.textContent == "Delete"); | |
if (!dBtn) { | |
document.elementFromPoint(0, 0).click(); | |
return; | |
} | |
p = waitForElement('div[data-testid="confirmationSheetConfirm"]'); | |
dBtn.click(); | |
const cBtn = await p; | |
cBtn.click(); | |
} | |
async function unRetweet(ele) { | |
let p = waitForElement('div[data-testid="unretweetConfirm"]'); | |
ele.click(); | |
const dd = await p; | |
dd.click(); | |
} | |
(async function deleteAll() { | |
console.clear(); | |
console.log("Deleting all"); | |
const ul = Array.from(document.querySelectorAll('div[data-testid="unlike"]')); | |
console.log("unLike", ul.length); | |
if (ul.length > 0) { | |
ul[0].click(); | |
setTimeout(deleteAll, 1); | |
return; | |
} | |
const ut = Array.from(document.querySelectorAll('div[data-testid="unretweet"]')); | |
console.log("unRetweet", ut.length); | |
if (ut.length > 0) { | |
await unRetweet(ut[0]); | |
setTimeout(deleteAll, 1); | |
return; | |
} | |
const cs = Array.from(document.querySelectorAll('div[data-testid="caret"]')); | |
console.log("tweets", cs.length); | |
if (cs.length > 0) { | |
await deleteTweet(cs[0]); | |
setTimeout(deleteAll, 1); | |
return | |
} | |
window.scrollBy(0, document.body.scrollHeight); | |
console.log("Scheduling"); | |
setTimeout(deleteAll, 10000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment