Skip to content

Instantly share code, notes, and snippets.

@davidhcefx
Last active October 26, 2024 15:49
Show Gist options
  • Save davidhcefx/b53b8e23172cc9fe936963587429a0fd to your computer and use it in GitHub Desktop.
Save davidhcefx/b53b8e23172cc9fe936963587429a0fd to your computer and use it in GitHub Desktop.
Browser script to search Facebook Messenger message by date

How to Search Facebook Messenger by Date

Answered in this thread

Until now, Facebook Messenger still doesn't offer an option to filter messages within a specific date range. The only option left is to scroll manually through the entire message thread, either by pressing Page up or Ctrl + Home, which is very very time-consuming.

So, I wrote a script to automate all the tedious stuff!

  1. In Chrome, press Cmd+Option+C (or Ctrl+Shift+C on Windows) and click on a "timestamp message" in Messenger.

    1. A "timestamp message" is the timestamp that are sometimes inserted at the top of the messages.
    2. For example, in Chinese it might appear as "2023/09/26 上午12:51".
  2. Switch to the Console tab, and paste the following:

/* select row div */
x = $0; while (x.tagName !== 'DIV' || x.role !== 'row') { x = x.parentNode; } while (x.parentNode.children.length <= 3) { x = x.parentNode; }
  1. Assuming the timestamp message in your language appears as "YYYY/MM/DD" (eg. "2023/09/26"). Paste the following to Console, and change the TARGET to TARGET = ['YYYY/MM/'].
    1. Facebook tends to represent timestamps in different formats.
    2. For example, in Chinese it might appear as "2023年9月26日 上午12:51" for dates that are near but change to "2022/08/17 上午10:23" when the date is far away.
    3. If you are not sure what format it might be, you can list all the possibilities, eg. TARGET = ['2023/09/', '2023年9月'].
/* set the month; you can list all the possibilities here */
TARGET = ['2023/09/'];
intId = setInterval(() => {
  x = x.parentNode.firstChild; x.scrollIntoView();
  for (let n of x.parentNode.childNodes) {
    d = n.querySelector('div[data-scope="date_break"]');
    for (let t of TARGET) {
      if (d && d.innerText.startsWith(t)) { clearInterval(intId); return; }
    }
  }
  while (x.parentNode.children.length > 1000) { x.parentNode.lastChild.remove(); }
}, 1000);
  1. If anything goes wrong, to make it stop simply paste the following to the Console.
clearInterval(intId);

DISCLAIMER: Please use it at your own risk. If you feel unsure please stop and seek for other approach.

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