Skip to content

Instantly share code, notes, and snippets.

@mi-lee
Last active July 14, 2025 17:09
Show Gist options
  • Select an option

  • Save mi-lee/54a781dea746b947f36d8544682d3cdf to your computer and use it in GitHub Desktop.

Select an option

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)
@omgcheese

Copy link
Copy Markdown

Time to delete everything

@andrewtheis

andrewtheis commented Dec 18, 2018

Copy link
Copy Markdown

Here's an update that also supports removing reactions:

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("UNLIKED");
      } else if (editButton.textContent == 'Remove Reaction') {
      	editButton.click();   // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
        console.log("REACTION REMOVED");
      } else {
        console.log("IGNORED")
      }
    }
  }
}

ghost commented Jun 30, 2019

Copy link
Copy Markdown

Hello. It is not working. I copied and pasted the code in "Console" and once I entered the code it says "undefined". What's the problem. Please help me. Thank you! :D

@MrBananaLord

MrBananaLord commented Jan 2, 2020

Copy link
Copy Markdown

you need to set the proper date in the options and @andrewtheis there is a typo, seems like now it's "Remove reaction" without capital R in the reaction :)

@lanceLMD15 run:

var options = {
  year: '2018', // MIND THE YEAR
  limit: 0 // use 1000 if you want to throttle it
};

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("UNLIKED");
      } else if (editButton.textContent == 'Remove reaction') {
      	editButton.click();   // COMMENT OUT IF YOU WANT TO TEST IT OUT WITHOUT ACTUALY DELETING
        console.log("REACTION REMOVED");
      } else {
        console.log("IGNORED")
      }
    }
  }
}

delete_hide_unlike(options)

@WiliTest

WiliTest commented Apr 4, 2020

Copy link
Copy Markdown

Any idea how to unlike only specific items using keyword and dates ? (Eg: unlike everything from website.com from 2017 to 2018)

@Lanterfanten

Copy link
Copy Markdown

Tip: Doesn't seem to work in the "new" FB design. FB removed the option to switch to the old layout too. But... if you manage a page or group, go to that page, and use the link top-left to switch back to the "old" interface for 48 hours.

brave_2020-10-23_15-07-39

@KimberlyShein

Copy link
Copy Markdown

Is there an update on this? But only for removing "likes and reactions" BUT not comments?
Thank you. :)

@maxi-jazz

Copy link
Copy Markdown

Could anybody please explain, how the coding needs to be changed and how to find out new object names with the new facebook website?

@tazihad

tazihad commented Aug 27, 2021

Copy link
Copy Markdown

can you please update the script?

@croge2k

croge2k commented Sep 3, 2021

Copy link
Copy Markdown

agreed - this is just what i"m looking for - but even with the "updated" script a few posts down from the top - i define the year and still get the undefined "error" at the bottom

@aalyassin

Copy link
Copy Markdown

Hello All
This is exactly what I was looking for but, can anyone please tell us where exactly to run the script? It may sound silly but I don't where to run it.

Thank you all.

@Lanterfanten

Copy link
Copy Markdown

@aalyassin - I don't think the script works at the moment, but this is how you're supposed to 'run' scripts.

open the script in an editor. change any options as required. copy the script.
open the appropriate FB page in your browser.
open the developer tools (F12), select console in the menu
paste the script into the console window/section.

@aalyassin

Copy link
Copy Markdown

@Lanterfanten Thank you.

@TobiaszCudnik

Copy link
Copy Markdown

This worked for me to unlike stuff (connections => pages, page likes...). May work for other logs too.

async function clear_fb() {
    var rows = document.querySelectorAll('.kvgmc6g5 > .l9j0dhe7 .cypi58rs i')

    for (const row of rows) {
        // open
        row.click()
        // wait
        await new Promise( resolve => {
            setTimeout( () => {
                resolve()
            }, 100)
        })
        // confirm
        document.querySelector('[role=menu] [role=menuitem]').click()
    }
}
clear_fb()

@Tharwat96

Copy link
Copy Markdown

@TobiaszCudnik Thank you! works flawlessly 😌

@Meligy

Meligy commented Feb 28, 2022

Copy link
Copy Markdown

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

Meligy commented Mar 27, 2022

Copy link
Copy Markdown

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

@urbie4

urbie4 commented Apr 6, 2022

Copy link
Copy Markdown

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! :)

ghost commented May 15, 2022

Copy link
Copy Markdown

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

scofielda commented Jul 18, 2022

Copy link
Copy Markdown

@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
Copy Markdown

@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!

@yllekz

yllekz commented Feb 7, 2025

Copy link
Copy Markdown

Does this script still work?

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