Created
September 28, 2011 14:31
-
-
Save youpy/1248080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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