Skip to content

Instantly share code, notes, and snippets.

@lethak
Last active October 10, 2019 11:26
Show Gist options
  • Save lethak/2c7a11eedbe1eded9b287433f718d7d5 to your computer and use it in GitHub Desktop.
Save lethak/2c7a11eedbe1eded9b287433f718d7d5 to your computer and use it in GitHub Desktop.
Delete Facebook Activity Log Timeline Post
/*
REQUIREMENTS:
You must use Facebook in the English language
HOW-TO:
First, open your FaceBook Activity Log Page (https://www.facebook.com/<YOUR PROFILE HANDLE>/allactivity?privacy_source=activity_log_top_menu&entry_point=www_top_menu_button#)
Then, select a Year and scroll to bottom until you reached "January" for this year.
Then, copy/paste the following code into the javascript console (F12) and press ENTER.
NOTES:
This will not delete Likes, only your posted content.
The current month is also in the scope to be removed since the page opens on it.
*/
window.ltk_deleteFacebookActivityLogTimelinePost_stop = function() {
if (window.ltk_loopHandler) {
clearInterval(window.ltk_loopHandler)
window.ltk_loopHandler = null
}
}
window.ltk_deleteFacebookActivityLogTimelinePost_start = function() {
window.ltk_deleteFacebookActivityLogTimelinePost_stop()
const loopIntervalMs = 750
window.ltk_loopHandler = null
const EditButtonSelector = 'a._42ft._42gx[role="button"][aria-label="Edit"]'
const EditButtonDeleteButtonSelector = 'a[rel="async-post"][ajaxify^="/ajax/timeline/all_activity/remove_content.php?action=remove_comment"]'
const EditButtonDeleteButtonSelector2 = 'a[rel="async-post"][ajaxify^="/ajax/timeline/delete/confirm?identifier="]'
const TimeLineDeleteModalConfirmButtonSelector = 'form[action^="/ajax/timeline/delete"] button.layerConfirm[type="submit"][value="1"]'
const TimeLineDeleteModalFormSavingSelector = 'form.async_saving[action^="/ajax/timeline/delete"]'
const ExceptionDialogCancelButtonSelector = 'div[data-testid="exception_dialog"] a.layerCancel[action="cancel"][role="button"]'
const clickDeleteButtonOnEditHoverMenu = function () {
console.log('clickDeleteButtonOnEditHoverMenu...')
for (let selector of [EditButtonDeleteButtonSelector, EditButtonDeleteButtonSelector2]) {
document.querySelectorAll(selector).forEach((v, i) => {
console.log('now clicking ... ', v)
v.style.backgroundColor = 'red'
v.parentElement.classList.add('selected')
v.parentElement.click()
v.click()
v.setAttribute('rel', 'ltkDone_async-post')
})
}
}
const isDeleteModalConfirmOpened = function () {
return !!(document.querySelectorAll(TimeLineDeleteModalConfirmButtonSelector).length > 0)
}
const isDeleteModalConfirmSavingOpened = function () {
return !!(document.querySelectorAll(TimeLineDeleteModalFormSavingSelector).length > 0)
}
const isExceptionDialogOpened = function () {
return !!(document.querySelectorAll(ExceptionDialogCancelButtonSelector).length > 0)
}
const processElemQueue = []
// Add to queue ...
document.querySelectorAll(EditButtonSelector).forEach((v, i) => {
//v.setAttribute('aria-label', 'Edit X')
processElemQueue.push(v)
})
window.ltk_loopHandler = setInterval(() => {
if (isExceptionDialogOpened()) {
console.log('Closing exception dialog...')
document.querySelectorAll(ExceptionDialogCancelButtonSelector).forEach((v, i) => {
v.style.backgroundColor = 'red'
v.click()
})
}
if (isDeleteModalConfirmSavingOpened()) {
console.log('Still saving, waiting...')
return null
}
if (isDeleteModalConfirmOpened()) {
console.log('Modal opened, trying to click DELETE...')
document.querySelectorAll(TimeLineDeleteModalConfirmButtonSelector).forEach((v, i) => {
v.style.backgroundColor = 'red'
console.log('Clicked elem ...', v)
v.click()
})
return null
}
console.log('Items remaining: ', processElemQueue.length)
if (processElemQueue.length > 0) {
const elem = processElemQueue.pop()
console.log('Dequeuing... item: ', elem)
elem.style.backgroundColor = 'red'
elem.scrollIntoView(true)
setTimeout(() => {
elem.click()
clickDeleteButtonOnEditHoverMenu()
}, 20)
setTimeout(() => {
clickDeleteButtonOnEditHoverMenu()
}, 110)
} else {
console.warn('Clearing window.ltk_loopHandler !', window.ltk_loopHandler)
window.ltk_deleteFacebookActivityLogTimelinePost_stop()
}
}, loopIntervalMs)
}
ltk_deleteFacebookActivityLogTimelinePost_start()
//ltk_deleteFacebookActivityLogTimelinePost_stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment