Skip to content

Instantly share code, notes, and snippets.

@mi-lee
Last active May 9, 2024 01:00
Show Gist options
  • Save mi-lee/54a781dea746b947f36d8544682d3cdf to your computer and use it in GitHub Desktop.
Save mi-lee/54a781dea746b947f36d8544682d3cdf to your computer and use it in GitHub Desktop.
Bulk delete, unlike, hide, or remove Facebook actions (in Activity Feed) by year.
// DISCLAIMER: I'VE ONLY RUN THIS SCRIPT ON MY OWN ACCOUNT ONLY. PROCEED/USE WITH RISK! I MADE THIS SCRIPT IN 20 MINUTES SO BE WARNED!
// On the other hand, I've deleted 50,000 comments in a matter of minutes so it's been pretty damn handy
// 1. Go to Activity feed, like facebook.com/<username>/allactivity
// 2. Navigate to specific section of FB, like "Likes and Reactions" or "Comments",
// like https://www.facebook.com/<username>/allactivity?privacy_source=activity_log&log_filter=cluster_<clusterid>
// 3. Navigate to year that you want to batch delete. You may need to scroll a little bit to let it load
// 4. Once you enter this there's no going back!!
// deletes, hides, and unlikes posts all within a specific year (in options.year)
function delete_hide_unlike(options) {
var rows = document.querySelectorAll('#facebook #year_' + options.year + ' ._42fu');
for (var k = rows.length - 1; k >= options.limit; k--) {
var row = rows[k];
var rowButton = row.click();
var editButtons = document.querySelectorAll('._54nh');
for (var j = editButtons.length - 1; j >= options.limit; j--) {
var editButton = editButtons[j];
if (!editButton) {
console.log('Nope!');
break;
}
if (editButton.textContent == 'Delete') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("DELETED");
} else if (editButton.textContent == 'Hidden from timeline') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("HIDDEN");
} else if (editButton.textContent == 'Unlike') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("UNLIKE");
} else {
console.log("IGNORED")
}
}
}
}
var options = {
year: '2007',
limit: 0, // use 1000 if you want to throttle how much to delete
}
delete_hide_unlike(options);
// unlikes and deletes anything that is globally public, by year (set in options.year)
function unlike_delete_globally_public_posts(options) {
var rows = document.querySelectorAll('#year_' + options.year + ' *[aria-label="Public"]')
for (var i = 0; i < rows.length; i++) {
var global_like = rows[i]
var likeButton = global_like.parentElement.parentElement.parentElement.querySelector('._42fu')
likeButton.click();
var editButtons = document.querySelectorAll('._54nh');
for (var j = editButtons.length - 1; j >= options.limit; j--) {
var editButton = editButtons[j];
if (!editButton) {
console.log('Nope!');
break;
} else if (editButton.textContent == 'Delete') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("DELETED");
} else if (editButton.textContent == 'Unlike') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("UNLIKE");
} else {
console.log("No action")
}
}
}
}
var options = {
year: '2009',
limit: 0 // use 1000 if you want to throttle it
}
unlike_delete_globally_public_posts(options)
@Meligy
Copy link

Meligy commented Feb 28, 2022

This clears a specific date:

START

await (async function clear_fb(dateTextFilter) {
  var count = 0;
  var accumulator = 0;

  async function wait(time = 16) {
    await new Promise((resolve) => {
      setTimeout(() => {
        resolve();
      }, time);
    });
  }

  async function try_click(element) {
    if (!element) return;
    try {
      element.scrollTo();
      await wait(1);
    } catch (e) {}
    try {
      element.focus();
      await wait(1);
    } catch (e) {}
    try {
      element.click();
      await wait();
    } catch (e) {}
  }

  async function do_clear() {
    window.scrollTo(0, document.body.scrollHeight);
    await wait(500);

    var parent = [...document.querySelectorAll(".bi6gxh9e")].filter((e) =>
      e.innerText.includes(dateTextFilter)
    )[0].parentElement;
    var rows = [
      ...parent.querySelectorAll(".kvgmc6g5 > .l9j0dhe7 .cypi58rs i"),
    ];

    console.log("Discovered " + rows.length + " rows");

    for (const row of rows) {
      await try_click(row);
      console.log(row.parentElement.parentElement.parentElement.innerText);
      var unlike = document.querySelector("[role=menu] [role=menuitem]");
      await try_click(unlike);

      var ok = [
        ...document.querySelectorAll(
          ".a8c37x1j.ni8dbmo4.stjgntxs.l9j0dhe7.ltmttdrg.g0qnabr5"
        ),
      ].filter((e) => e.innerText.includes("OK"))[0];
      await try_click(ok);

      var x = [
        ...document.querySelectorAll(
          "div.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.pfnyh3mw.d2edcug0.hpfvmrgz.p8fzw8mz.pcp91wgn.iuny7tx3.ipjc6fyt > div > i"
        ),
      ][0];
      await try_click(x);
      row.parentElement.parentElement.parentElement.remove();
      await wait();
    }

    return rows.length;
  }

  do {
    window.scrollTo(0, 0);
    await wait();
    count = await do_clear();
    accumulator += count;
    console.log("Finished clearing " + accumulator + " rows");
  } while (count != 0);

  console.log("Done");
})("February 28, 2022");

END

Not future proof at all, but does the job for now.

@Meligy
Copy link

Meligy commented Mar 27, 2022

@DeanyBox you run it in the browser console directly (in Developer Tools).

@urbie4
Copy link

urbie4 commented Apr 6, 2022

Wish I'd had this years ago; I tried all sorts of plugins and scripts to delete FB activity, and some of them worked quite well -- for a short time, until Zucky changed the code so they wouldn't work. Moot point now, though, because I finally utilized the nuclear option and deleted my FB, Insta, and WhatsApp about six months ago. You can do it, too! :)

Copy link

ghost commented May 15, 2022

Can someone please show me how this is supposed executed in console, I copied and pasted into console but i think the reason its not working is because i might be adding text that i shouldn’t be?

// deletes, hides, and unlikes posts all within a specific year (in options.year)
function delete_hide_unlike(options) {
var rows = document.querySelectorAll('#facebook #year_' + options.year + ' ._42fu');
for (var k = rows.length - 1; k >= options.limit; k--) {
var row = rows[k];
var rowButton = row.click();
var editButtons = document.querySelectorAll('._54nh');
for (var j = editButtons.length - 1; j >= options.limit; j--) {
var editButton = editButtons[j];
if (!editButton) {
console.log('Nope!');
break;
}
if (editButton.textContent == 'Delete') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("DELETED");
} else if (editButton.textContent == 'Hidden from timeline') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("HIDDEN");
} else if (editButton.textContent == 'Unlike') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("UNLIKE");
} else {
console.log("IGNORED")
}
}
}
}
var options = {
year: '2007',
limit: 0, // use 1000 if you want to throttle how much to delete
}
delete_hide_unlike(options);

// unlikes and deletes anything that is globally public, by year (set in options.year)
function unlike_delete_globally_public_posts(options) {
var rows = document.querySelectorAll('#year_' + options.year + ' *[aria-label="Public"]')
for (var i = 0; i < rows.length; i++) {
var global_like = rows[i]
var likeButton = global_like.parentElement.parentElement.parentElement.querySelector('._42fu')
likeButton.click();
var editButtons = document.querySelectorAll('._54nh');
for (var j = editButtons.length - 1; j >= options.limit; j--) {
var editButton = editButtons[j];
if (!editButton) {
console.log('Nope!');
break;
} else if (editButton.textContent == 'Delete') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("DELETED");
} else if (editButton.textContent == 'Unlike') {
editButton.click(); // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
console.log("UNLIKE");
} else {
console.log("No action")
}
}
}
}
var options = {
year: '2009',
limit: 0 // use 1000 if you want to throttle it
}
unlike_delete_globally_public_posts(options)

@scofielda
Copy link

scofielda commented Jul 18, 2022

@mi-lee Hello :) I have tried all scripts but it's not working. I think it needs an update to the new Facebook, Could you please recheck the script? I just need interactions (post likes/comment likes) remover. Thanks in advance :)

@scofielda
Copy link

@Meligy Hello :) the script you wrote is not working, could you please update it, just specific to the year (not specific to a date)? It gave me undefined result, as of a specific date too. Thanks!

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