Skip to content

Instantly share code, notes, and snippets.

@cers
Created June 15, 2009 12:49
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 cers/130085 to your computer and use it in GitHub Desktop.
Save cers/130085 to your computer and use it in GitHub Desktop.
// NOTE: Remember to fill in login credentials - in the future, this will be stored persistently via simple_storage probably...
Components.utils.import("resource://jetpack/ubiquity-modules/utils.js");
var TwitterJetpack = {
last: 0,
queue: [],
request: { type: "GET",
url: "http://twitter.com/statuses/friends_timeline.json",
dataType: "json",
error: function() {jetpack.notifications.show({"title":"TwitterJetpack","body":"Error fechting updates"});},
username: "",
password: ""
},
getUpdates: function getUpdates() {
var req = TwitterJetpack.request;
req.success = function parseTwitterUpdates(data) {
for (var d=data.length-1; d>-1; d--)
if (data[d].id > TwitterJetpack.last) {
console.log(data[d].id);
TwitterJetpack.queue.push({"title":data[d].user.name,"body":data[d].text, "icon":data[d].user.profile_image_url.replace(/\\/g,"")});
}
TwitterJetpack.last = data[0].id;
},
jQuery.ajax(req);
TwitterJetpack.notify();
setTimeout(TwitterJetpack.getUpdates,2*60*1000);
},
notify: function() {
if (TwitterJetpack.queue.length > 0) {
jetpack.notifications.show(TwitterJetpack.queue.shift());
setTimeout(TwitterJetpack.notify,10*1000);
}
}
};
jetpack.statusBar.append({
html: '<img style="margin-top: 3px" src="http://assets1.twitter.com/images/favicon.ico">',
width: 16,
onReady: function(widget) {
var req = TwitterJetpack.request;
req.success = function initLast(data) {TwitterJetpack.last = data[0].id;};
jQuery.ajax(req);
$(widget).click(function(){Utils.openUrlInBrowser("http://twitter.com");});
setTimeout(TwitterJetpack.getUpdates,62*1000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment