Skip to content

Instantly share code, notes, and snippets.

@youpy
Created September 28, 2011 14:31
Show Gist options
  • Save youpy/1248080 to your computer and use it in GitHub Desktop.
Save youpy/1248080 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Facebook.com: notify changes of online friends
// @namespace http://buycheapviagraonlinenow.com/
// @include http://www.facebook.com/
// ==/UserScript==
var notifyServerUrl = 'http://localhost:5678/', // https://gist.github.com/1021283
current, previous = [];
setInterval(function() {
current = Array.map(document.querySelectorAll('.active'), function(item) {
return item.textContent;
});
notify(only(current, previous), 'online');
notify(only(previous, current), 'offline');
previous = current.concat();
}, 5000);
function only(a, b) {
var result = [];
a.forEach(function(item) {
if(b.indexOf(item) == -1) {
result.push(item);
}
});
return result;
}
function notify(names, behavior) {
if(names.length > 0) {
var msg = [names.join(', '), names.length > 1 ? 'are' : 'is', behavior].join(' ');
document.createElement('img')
.src = notifyServerUrl + '?text=' + 'Facebook: ' + encodeURIComponent(msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment