From e1473deaeb34dfc5453af5b83c65eaf818a4060a Mon Sep 17 00:00:00 2001 From: Stevan Lohja Date: Wed, 3 Jan 2024 10:37:59 -0500 Subject: [PATCH] feat: more scripts --- README.md | 2 +- rm_likes.js | 28 ++++++++++++++++++++++++++++ rm_posts_and_reposts.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 rm_likes.js create mode 100644 rm_posts_and_reposts.js diff --git a/README.md b/README.md index 1a9e139..eacb46b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Script to delete all X / Twitter tweets. (Credits go to ChatGPT, I didn't write - Open Chrome and go to your X profile (https://x.com/USERNAME/with_replies) - Open Chrome Developer Console. Copy/Paste the code: -``` +```js const deleteAllTweets = async () => { const processedButtons = new Set(); const getDeleteButtons = () => Array.from(document.querySelectorAll('[data-testid="tweet"] [data-testid="caret"]')); diff --git a/rm_likes.js b/rm_likes.js new file mode 100644 index 0000000..5b101ed --- /dev/null +++ b/rm_likes.js @@ -0,0 +1,28 @@ +const removeLikes = async () => { + const processedButtons = new Set(); + const getLikeButtons = () => Array.from(document.querySelectorAll('[data-testid="like"]')); + const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + + while (true) { + const likeButtons = getLikeButtons().filter(button => !processedButtons.has(button)); + + if (likeButtons.length === 0) break; + + for (const button of likeButtons) { + processedButtons.add(button); + button.click(); + await delay(3000); + + const undoLikeButton = document.querySelector('[data-testid="unlike"]'); + + if (undoLikeButton) { + undoLikeButton.click(); + await delay(3000); + } + } + } + + console.log('All likes removed successfully!'); +}; + +removeLikes(); \ No newline at end of file diff --git a/rm_posts_and_reposts.js b/rm_posts_and_reposts.js new file mode 100644 index 0000000..f8b7acb --- /dev/null +++ b/rm_posts_and_reposts.js @@ -0,0 +1,40 @@ +const deleteAllPostsAndReposts = async () => { + const processedButtons = new Set(); + const getDeleteButtons = () => Array.from(document.querySelectorAll('[data-testid="tweet"] [data-testid="caret"]')); + const getUnretweetButtons = () => Array.from(document.querySelectorAll('[data-testid="tweet"] [data-testid="unretweet"]')); + const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + + while (true) { + const deleteButtons = getDeleteButtons().filter(button => !processedButtons.has(button)); + const unretweetButtons = getUnretweetButtons().filter(button => !processedButtons.has(button)); + + if (deleteButtons.length === 0 && unretweetButtons.length === 0) break; + + for (const button of deleteButtons) { + processedButtons.add(button); + button.click(); + await delay(250); + + const menuItems = Array.from(document.querySelectorAll('[role="menuitem"]')); + const deleteOption = menuItems.find(item => item.textContent === 'Delete'); + + if (deleteOption) { + deleteOption.click(); + document.querySelector('[data-testid="confirmationSheetConfirm"]')?.click(); + await delay(3000); + } + } + + for (const button of unretweetButtons) { + processedButtons.add(button); + button.click(); + await delay(250); + document.querySelector('[data-testid="unretweetConfirm"]')?.click(); + await delay(3000); + } + } + + console.log('All posts and reposts deleted successfully!'); +}; + +deleteAllPostsAndReposts(); \ No newline at end of file