Created
December 27, 2018 09:50
-
-
Save af-inet/fc287e6e23e8e33dfef0c160fcb10ec8 to your computer and use it in GitHub Desktop.
delete all your facebook posts
This file contains hidden or 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
| /* | |
| HOW TO USE THIS PROGRAM | |
| 1. Log in to facebook, and go to your "Activity Feed". | |
| 2. Scroll down a little bit so you have posts on the screen. | |
| 3. Paste this code into the developer console. | |
| 4. Execute deletePost() in the console. | |
| 5. Done; watch as the bot will delete roughly 1 post every 4 seconds. | |
| 6. Refresh the page to disable the script. | |
| */ | |
| function clickConfirmDeleteButton() { | |
| var confirmDeleteButton = findConfirmDeleteButton(); | |
| // show the user we're about to click this button | |
| confirmDeleteButton.style.border = "solid 2px red" | |
| setTimeout(function () { | |
| // finally we can delete this post | |
| confirmDeleteButton.click(); | |
| // wait for the post to disappear | |
| setTimeout(function () { | |
| // the post was deleted, no need to increment the skip counter | |
| deletePost() | |
| }, 4000) | |
| }, 100) | |
| } | |
| function findConfirmDeleteButton() { | |
| var elements = document.querySelectorAll('button[type="submit"]'); | |
| for (var i = 0; i < elements.length; i++) { | |
| if (elements[i].textContent.toLowerCase() === "delete") { | |
| return elements[i]; | |
| } | |
| } | |
| throw new Error("failed to find confirm delete button") | |
| } | |
| function findDeleteButton() { | |
| var elements = [] | |
| var iterator = document.evaluate("//a[contains(., 'Delete')]", document, null, XPathResult.ANY_TYPE, null); | |
| var element = null; | |
| while (element = iterator.iterateNext()) { | |
| elements.push(element) | |
| } | |
| if (elements.length <= 0) { | |
| throw new Error("did not find delete button") | |
| } | |
| return elements[elements.length - 1] | |
| } | |
| function clickDeleteButton() { | |
| var deleteButton = findDeleteButton() | |
| // show the user we're about to click this button | |
| deleteButton.style.border = "solid 2px red" | |
| setTimeout(function () { | |
| deleteButton.click() | |
| setTimeout(clickConfirmDeleteButton, 1000); | |
| }, 100) | |
| } | |
| function findNextPost() { | |
| var elements = document.querySelectorAll('[data-tooltip-content="Edit"], [data-tooltip-content="Allowed on timeline"], [data-tooltip-content="Hidden from timeline"]'); | |
| if (elements.length > 0) { | |
| return elements[0]; | |
| } | |
| return null; | |
| } | |
| function deletePost() { | |
| var target = findNextPost() | |
| if (target) { | |
| // show the user we're about to click this button | |
| target.style.border = "solid 2px red"; | |
| setTimeout(function () { | |
| target.click(); | |
| // don't click that shit again | |
| target.parentElement.removeChild(target); | |
| setTimeout(clickDeleteButton, 100); | |
| }, 100) | |
| } | |
| else { | |
| console.log("failed to find a post, scrolling down and starting over. We might have run out of posts..."); | |
| // this part is annoying because we need to scroll down and wait for new posts to load, | |
| // so we scroll, wait, scroll, wait, etc... | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| deletePost() | |
| }, 1000) | |
| }, 1000); | |
| }, 1000); | |
| }, 1000); | |
| }, 1000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I went to https://business.facebook.com/latest/posts/published_posts/ and ran the following script to delete all the posts on page, worked flawlessly.
Enjoy.