Skip to content

Instantly share code, notes, and snippets.

@rissole
Created September 8, 2014 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rissole/174b242550a4cc7f7fa6 to your computer and use it in GitHub Desktop.
Save rissole/174b242550a4cc7f7fa6 to your computer and use it in GitHub Desktop.
[Facebook Gags Collection]: Master script
// ==UserScript==
// @name Facebook Gags Master
// @namespace gags
// @description Gag factory. But seriously, OnMessageReceived hook for Facebook.
// @include https://www.facebook.com/
// @include https://www.facebook.com/?*
// @version 1
// @grant none
// ==/UserScript==
var _hooks = [];
requireLazy(["require", "MercuryThreadInformer", "CurrentUser"], function (a, b, c) {
var threadInformer = a('MercuryThreadInformer').get();
threadInformer.subscribe('messages-received', function (_, messageObject) {
messageObject = messageObject[Object.keys(messageObject)[0]][0];
for (var i = 0; i < _hooks.length; ++i) {
_hooks[i](messageObject, c.getID());
}
})
});
/**
* Add a new message hook
* fn: the function to be called when a message is received.
* args: msg - the message object.
* msg.body is the message text.
msg.author is who sent the message.
currentUser - the ID of the current Facebook user.
*/
function addMessageHook(fn) {
if (typeof(fn) !== "function") {
throw "addMessageHook expects a function";
}
_hooks.push(fn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment