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.
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();
- 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.
- 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.
Hello - this is my first Github post, so go easy on me :)
I found the code mentioned above was quite slow to run, particularly with Marketplace chats - but did work. It's worth noting I had an exceptionally high number of chats (minimum 2000 plus).
Obviously this is down to the set timeout, the iteration of the function, lack of caching etc. I suggest using the following code which uses requestAnimationFrame, caches 'div[role=menuitem]' etc. There is further improvements that could be made here but this worked a lot quicker for me; not lightning speed but instantly reduces the iteration time from 500ms to however long it takes the browser to be ready to repaint the screen.
(function run() { let all = document.querySelectorAll('div[aria-label="Menu"]'); if (all.length == 0) return; let a = all[1]; a.click(); let menuitems = document.querySelectorAll('div[role=menuitem]'); let archiveChatRegex = /Archive chat/; for (let i = 0; i < menuitems.length; i++) { if (archiveChatRegex.test(menuitems[i].innerText)) { menuitems[i].click(); } } requestAnimationFrame(run); })();
VERSION with white space removed:
(function run(){let all=document.querySelectorAll('div[aria-label="Menu"]');if(all.length==0)return;let a=all[1];a.click();let menuitems=document.querySelectorAll('div[role=menuitem]');let archiveChatRegex=/Archive chat/;for(let i=0;i<menuitems.length;i++){if(archiveChatRegex.test(menuitems[i].innerText)){menuitems[i].click();}}requestAnimationFrame(run);})();
Notes
I did not need to paste the http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js contents.
The Dev Console will throw a "[Violation] 'requestAnimationFrame' handler took ms" error for each chat but this can be ignored