Skip to content

Instantly share code, notes, and snippets.

@oozzal
Last active August 29, 2015 14:07
Show Gist options
  • Save oozzal/4432e801a2c8db106f83 to your computer and use it in GitHub Desktop.
Save oozzal/4432e801a2c8db106f83 to your computer and use it in GitHub Desktop.
(function() {
var users = [
{
id: '100001671834399',
name: 'Krishna Bashyal',
nickname: 'Krrish',
sound: false
},
{
id: '100001630484101',
name: 'Suraj Adhikari',
nickname: 'Suraj',
sound: false
},
{
id: '100001465984640',
name: 'Prakash Silwal',
nickname: 'Prakash',
sound: false
}
]
var accessToken = '' //Please generate a long term access token for fb and put here
var baseUrl = 'https://graph.facebook.com/fql?';
var ids = users.map(function(user){ return user.id; }).join(',');
baseUrl += ("q=SELECT name, online_presence, uid, sex FROM user WHERE uid IN(" + ids + ")");
baseUrl += '&access_token=' + accessToken;
var req = new XMLHttpRequest();
var notify = function(data) {
if(data.error) {
return alert('Something Went Wrong With Online Checker !')
}
data.data.forEach(function(user) {
user.uid += ""; //Convert to string
if( (user.online_presence == 'active' || user.online_presence == 'idle') && localStorage[user.uid] !== "true" ) {
localStorage[user.uid] = "true";
//Select the nickname of user
var nickname = user.name;
users.forEach(function(u) {
if(u.id === user.uid) {
nickname = u.nickname;
}
})
var gender = (user.sex === 'male')? 'him' : 'her';
var picurl = 'https://graph.facebook.com/' + user.uid + '/picture?width=200&height=200';
//@TODO: Play sound here
var n = window.webkitNotifications.createNotification(picurl, 'Hey! ' + nickname +' is Online', 'You may wanna hang out with ' + gender + ' !')
n.show();
n.onclick = function() {
window.open('http://facebook.com');
}
}
if(user.online_presence === 'offline') {
localStorage[user.uid] = "false";
}
})
}
req.addEventListener('load', function(e) {
var data = JSON.parse(e.currentTarget.response);
notify(data);
})
setInterval(function() {
req.open('GET', baseUrl, true);
req.send();
}, 30 * 1000);
})();
{
"name": "Online Checker",
"version": "1.0.0",
"manifest_version": 2,
"description": "Online Checker",
"permissions": ["notifications", "background"],
"offline_enabled": true,
"minimum_chrome_version": "25",
"background": {
"scripts": ["checker.js"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment