Last Updated on June 13, 2023 EDT by Jordan
Too many Facebook Messages
I had a ton of Facebook Marketplace messages that I was annoyed with and wanted archived. So I found many resources online on using the Chrome console to run javascript to archive the messages.
Javascript Gist and More
I found a gist with the needed code, but it didn’t work. Upon reading the comments, there was updated code buried and another Github repository.
My modified code
I took the original code and modified it with ChatGTP. I had it limit the number of times the script would run, essentially, how many messages it would archive. I also added a delay, to make sure I didn’t get blocked by Facebook.
let executionCount = 0; function run() { if (executionCount >= 100) { return; } 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(); } } executionCount++; setTimeout(run, 200); // Delay of 1 second (1000 milliseconds) } run();