Skip to content

Instantly share code, notes, and snippets.

@DanTup
Last active October 17, 2023 21:51
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save DanTup/653b43079de26c249308 to your computer and use it in GitHub Desktop.
Delete all Facebook posts for a year
// Only tested in Chrome...
// Must browse to "Your Comments" (or "Your Likes") page of activity feed, then pre-load the year you want to delete
// and as many comments as possible (scroll down, they load lazily).
//
// I ACCEPT ABSOLUTELY NO RESPONSIBILITY FOR THIS DOING BAD STUFF. THE NEXT FACEBOOK DEPLOYMENT
// COULD WELL BREAK THIS, OR MAKE IT DO THINGS YOU DO NOT EXPECT. USE IT AS A STARTING POINT ONLY!
//
// It will start failing once it gets to the end, just reload the page and kick it off again.
var rows = document.querySelectorAll('#year_2012 .pam._5shk');
for (var k = 0; k < rows.length; k++) {
var row = rows[k];
var editButton = row.querySelector('.sp_DcMiPntlyW3.sx_042f0f');
if (!editButton) {
console.log('DONE!');
break;
}
editButton.click();
var possibleDeleteLinks = document.querySelectorAll('a[ajaxify]');
for (var i = 0; i < possibleDeleteLinks.length; i++) {
var link = possibleDeleteLinks[i];
if (link.getAttribute('ajaxify').startsWith('/ajax/timeline/all_activity/remove_content.php') && link.getAttribute('ajaxify').contains(row.id)) {
var prev = row.querySelector('.fsm');
if (prev != null)
console.log('DELETING (' + row.id + ') ' + prev.textContent);
else
console.log('DELETING (' + row.id + ')');
link.click();
break;
}
}
}
// Only tested in Chrome...
// Must browse to "Your Posts" page of activity feed, then pre-load the year you want to delete
// then paste into console and update the year in the selector.
//
// I ACCEPT ABSOLUTELY NO RESPONSIBILITY FOR THIS DOING BAD STUFF. THE NEXT FACEBOOK DEPLOYMENT
// COULD WELL BREAK THIS, OR MAKE IT DO THINGS YOU DO NOT EXPECT. USE IT AS A STARTING POINT ONLY!
//
// It will stop after a while, just reload the page and kick it off again.
setInterval(function() {
var row = document.querySelector('#year_2013 .pam._5shk');
var editButton = row.querySelector('.sp_DcMiPntlyW3.sx_042f0f');
if (!editButton) {
console.log('DONE!');
return;
}
editButton.click();
var possibleDeleteLinks = document.querySelectorAll('a[ajaxify]');
for (var i = 0; i < possibleDeleteLinks.length; i++) {
var link = possibleDeleteLinks[i];
if (link.getAttribute('ajaxify').startsWith('/ajax/timeline/delete/confirm') && link.getAttribute('ajaxify').endsWith(row.id)) {
var prev = row.querySelector('.fsm');
console.log('DELETING (' + row.id + ') ' + prev.textContent);
link.click();
setTimeout(function() {
var frms = document.querySelectorAll('form[action]');
for (var j = 0; j < frms.length; j++) {
var frm = frms[j];
if (frm.action.startsWith('https://www.facebook.com/ajax/timeline/delete?identifier=') && frm.action.endsWith(row.id)) {
var deleteButton = frm.querySelector('button');
console.log(deleteButton.textContent);
deleteButton.click();
row.remove();
break;
}
}
}, 250);
break;
}
}
}, 500);
@nf24eg
Copy link

nf24eg commented Oct 17, 2023

I'm sorry I'm not pro, may I know how to use this code? where I can paste it ?

@DanTup
Copy link
Author

DanTup commented Oct 17, 2023

@nf24eg

I'm sorry I'm not pro, may I know how to use this code? where I can paste it ?

You would paste it into the developer console, but this code is quite old and it's very likely (maybe even probable) that site changes will affect it. I wouldn't recommend using it unless you fully understand what it's doing and confirm the selectors are still correct for the links you want it to click (otherwise it might click links you don't want it to).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment