Custom Filter Function

The Custom Filter Function is a useful feature of the Message Retrieval Tool. It enables the user to conveniently specify which messages he wishes to retrieve for his own personal desire.

However, to use the custom filter function, the user requires knowledge of the JavaScript language. This page is a brief guide for users who know JavaScript on how to use the custom filter function. If you do not have knowledge of JavaScript, you can PM me on Reddit to clearly specify what you need the custom filter function to do, and I will respond as soon as possible.

From this point onwards, I would assume that you are fluent with JavaScript.

The custom filter function is created from your input:

function customFilterFunction(info) {
	// the code here is from your input; it should return true or false

When you use the button 'Retrieve', each chat message is filtered through 'customFilterFunction' in chronological order (beginning with the oldest chat message). If the function returns true, this message will be displayed in the table of results. If the function returns false, it will not.

The 'info' parameter is a JSON object that contains information about each chat message, as follows:

	"body": "1",
	"name": "LiveUpdate_1f9faa0c-12b0-11e4-ac25-12313b0c9247",
	"author": "ralgrado",
	"embeds": [],
	"created": 1406179638,
	"created_utc": 1406150838,
	"body_html": "<div class=\"md\"><p>1</p>\n</div>",
	"stricken": false,
	"id": "1f9faa0c-12b0-11e4-ac25-12313b0c9247"

The more important keys are "body" (raw content of the message), "author" (sender of the message), and "created_utc" (Unix time in UTC when the message was sent). The other keys are all rather self-explanatory.

For example, if you wish to display all messages that contains 5 characters, your input will be:

return info.body.length == 5;

Do take note that the body will also include extra whitespace and newlines. A custom filter function like this will give more accurate results:

return info.body.replace(/\n/g, '').trim().length == 5;

There is also a useful global function "getNo":

function getNo(str) {
	// returns the detected count in a string as a string
	// if no count was detected, returns null
	// Examples:
	//     "1 2 3 4" => "1234"
	//     "**5,678** wow" => "5678"
	//     "a very very long comment by /u/TOP_20" => null

For example, if you wish to filter messages with counts that end with "1234", you can input this:

var count = getNo(info.body);
return (count == null) ? false : count.endsWith("1234");

This results in the table displaying a list of messages with counts that end with "1234".

You can check for error messages thrown while executing custom filter functions in the browser console.

Custom filter functions can be versatile in finding what you need. For example, you can use the following piece of code to search for messages by /u/co3_carbonate that contains characters besides commas, numbers, dots, white spaces. In other words, it will result in a table of /u/co3_carbonate's messages that also contains other words.

if( != 'co3_carbonate') { return false; }
return info.body.match(/[^,.\d\s]/) != null;

As you can see, custom filter functions can be useful for your own needs, e.g. stalking.

Hopefully this guide has helped you. If you have any questions, feel free to PM me to clarify anything.