Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elibosley/6acb8850ad1f9f208c30d7c7e2842b89 to your computer and use it in GitHub Desktop.
Save elibosley/6acb8850ad1f9f208c30d7c7e2842b89 to your computer and use it in GitHub Desktop.
Archive all of the messages in your Facebook Messages Inbox

Facebook - Archive All Messages

Because who doesn't have an inbox full of "I got a new phone", event-based group chats, and old lingering messages in their Facebook Messages?

Surprisingly, Facebook has not implemented a way to archive many messages in your inbox. This script provides that solution.

UPDATE: THIS SCRIPT HAS BEEN UPDATED TO WORK AND IS TESTED AS WORKING (OCTOBER 31st, 2017 (spooky)). LET ME KNOW IF IT DOESN'T WORK FOR YOU!

Quickstart

Load Facebook Messages in a new tab.

Open the JavaScript console and paste the contents of jquery.min.js into the console.

Paste the contents of archive-all-facebook-messages.js into the console.

If you want to only test the results before actually running the archiving, there's a param for that:

archive_all(testOnly=true);

When you're ready to run for real:

archive_all();

Caveats

  • Currently only detects the list of messages visible to the user in the page. You can work around this by repeatedly scrolling the message list pane to the bottom until all messages are loaded. I plan to automate this step soon. (Maybe)
  • There is no way to whitelist certain messages from being archived. Currently, you can manually unarchive select messages from the archived view.
  • Sometimes the messages page remains cached after the script reloads it. Reloading it once by hand solves this.
function archive_all(testOnly) {
messages = $("._5blh")
console.log("Found", messages.length, "messages on messsenger.");
if (!testOnly) {
for (i = 0; i < messages.length; i++) {
try {
messages[i].click()// open dialog
$("li:contains('Archive')").last().click()
}
catch (TypeError) {
console.log("TypeError")
}
}
}
}
@hyiltiz
Copy link

hyiltiz commented Jan 20, 2020

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

@riginoommen
Copy link

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

New script works perfectly. Thanks

@szczepkacpra
Copy link

szczepkacpra commented Apr 19, 2020

I reproduced steps to the letter on Chrome's regular and Incognito mode (to rule out plugins interfering with the outcome) with no success.


Running archive_all(); on @hyiltiz 's code:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

returns:

VM1902:1 Uncaught ReferenceError: archive_all is not defined at <anonymous>:1:1

on both facebook.com/messages and messenger.com.


Running archive_all(); on on @hyiltiz 's code:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

on facebook.com/messages console returns:

Found 0 messages on messsenger.
undefined

on messenger.com console returns:

Found 20 messages on messsenger.
undefined

The only hidden conversations, are those which I manually hide following @surajk63 instructions.

FIX:

Change Facebook's language to English

@surajk63
Copy link

Scripts provided above doesn't work anymore.

Steps

  1. disable adblockers etc.
  2. paste and run jquery.min.js in the console.
  3. paste and run archive_all function definition in the console.
  4. scroll the Facebook Messenger chat panel on the right to the bottom with mouse manually.
  5. run archive_all();

Result

Correctly reports finding several hundred items, and after a while returns undefined but nothing happens to the chat. Nothing changes even after a refresh.
Tested in up-to-date Firefox Developer Version or Chrome.

Fix

Facebook renamed Archive to Hide. Use this:

(function run() {
  let all = document.querySelectorAll('div[aria-label="Conversation actions"]');
  if (all.length == 0) return;
  let a = all[0];
  a.click();
  setTimeout(() => {
    document.querySelectorAll('a[role=menuitem]').forEach(act => {
      if (act.innerText.match(/Hide/)) act.click();
    });
    run();
  }, 250);
})();

Or this:

function archive_all(testOnly) {

    messages = $("._5blh")
    console.log("Found", messages.length, "messages on messsenger.");
    if (!testOnly) {
        for (i = 0; i < messages.length; i++) {
            try {
                messages[i].click()// open dialog
                $("li:contains('Hide')").last().click()
            }
            catch (TypeError) {
                console.log("TypeError")
            }
        }
    }
}
archive_all();

New script works perfectly. Thanks

Try this one again, it should work.
I just tried today and it is working perfectly.

@szczepkacpra
Copy link

Try this one again, it should work.
I just tried today and it is working perfectly.

Thanks for answering. You sent me the same codes I have tried and quoted in my question.

Did you use top or the bottom code?
Did you go to facebook.com/messages or messenger.com?
What browser are you using?

@surajk63
Copy link

Try this one again, it should work.
I just tried today and it is working perfectly.

Thanks for answering. You sent me the same codes I have tried and quoted in my question.

Did you use top or the bottom code?
Did you go to facebook.com/messages or messenger.com?
What browser are you using?

I used the second code, first you have to load jquery code and then this function.
Then you can call the function as many times as you required.
You can try on both link: facebook.com/messages or messenger.com on chrome latest browser.

Thanks
-Suraj

@szczepkacpra
Copy link

szczepkacpra commented Apr 20, 2020

I found the solution: Facebook language has to be set to English. Otherwise the script won't work.

Thanks for getting involved @surajk63

@elibosley could you please include this information in your description?

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