Last active
October 15, 2019 21:31
-
-
Save quicoto/d568fd06fd141dd4dca578e38e98a0bb to your computer and use it in GitHub Desktop.
Delete Facebook Posts by year
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
/** | |
* HOW TO | |
* Replace XXXXXX by your username in the following url | |
* https://www.facebook.com/XXXXXX/allactivity?entry_point=privacy_settings&privacy_source=activity_log&log_filter=cluster_11&category_key=statuscluster | |
* Scroll down to a year. | |
* Important: you must scroll and see all the posts you want to delete before executing. | |
* The script will not auto scroll, will not auto load the posts. | |
* | |
* Set the year in the configuration. | |
* Copy the whole thing. | |
* Paste in the Dev Tools console. | |
* | |
* NOTICE: the code relies on Facebook's markup. The classnames or structure could chance any time. | |
* The code might not work but it is not dangerous either. Run safely. | |
*/ | |
/** | |
* Configuration | |
*/ | |
const year = '2013'; | |
/** | |
* Magic | |
*/ | |
const SELECTORS = { | |
container: `#year_${year}`, | |
editButton: `a[aria-label="Edit"]`, | |
openLayer: `.uiContextualLayerPositioner.uiLayer`, | |
deleteButton: `[rel="async-post"][role="menuitem"]`, | |
confirmButton: `button.layerConfirm` | |
} | |
const CLASSES = { | |
hidden: `hidden_elem` | |
} | |
setInterval (() => { | |
// Find the year container | |
const $container = document.querySelector(SELECTORS.container); | |
const $editButtons = $container.querySelectorAll(SELECTORS.editButton); | |
if ($editButtons.length > 0) { | |
const $button = $editButtons[0]; | |
// Open the edit with a delay | |
$button.click(); | |
const deleteTimeout = window.setTimeout(() => { | |
// Find the actual open layer. | |
// Once you delete an element the layer stays on the page | |
const $openLayers = document.querySelectorAll(SELECTORS.openLayer); | |
// Loop until you find one without the hidden class | |
$openLayers.forEach($layer => { | |
if (!$layer.classList.contains(CLASSES.hidden)) { | |
// This is the one, the one visible | |
const $deleteButton = $layer.querySelector(SELECTORS.deleteButton); | |
if ($deleteButton) { | |
$deleteButton.click(); | |
const confirmTimeout = window.setTimeout(() => { | |
const $confirmButton = document.querySelector(SELECTORS.confirmButton); | |
if ($confirmButton) { | |
$confirmButton.click(); | |
} | |
}, 3000); | |
} | |
} | |
}); | |
}, 1500); | |
} | |
}, 13000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment