Skip to content

Instantly share code, notes, and snippets.

@x4lldux
Created August 29, 2008 07:25
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 x4lldux/7929 to your computer and use it in GitHub Desktop.
Save x4lldux/7929 to your computer and use it in GitHub Desktop.
BLIP commands for Ubiquity
function getBlipLoggedUser() {
var url = "http://api.blip.pl/statuses";
var me = {};
var json = jQuery.ajax({
type: 'GET',
url: url,
async: false,
}).responseText;
var data = Utils.decodeJson(json);
me = {
nick: data[0].user_path.replace("/users/", ""),
path: data[0].user_path,
};
return me;
}
function getBlipContacts(callback) {
var url = "http://api.blip.pl/subscriptions";
var contacts = {};
var me = getBlipLoggedUser();
jQuery.getJSON(url, function(data) {
for each(var trackObj in data) {
var user = trackObj.tracked_user_path;
if(user!=me.path && !contacts.hasOwnProperty(user)) {
contacts[user] = user.replace("/users/", "");
}
user = trackObj.tracking_user_path;
if(user!=me.path && !contacts.hasOwnProperty(user)) {
contacts[user] = user.replace("/users/", "");
}
}
});
callback(contacts);
}
var noun_type_blip_contact = {
_name: "kontaktu blipa",
contactList: null,
callback: function(contacts) {
noun_type_blip_contact.contactList = contacts;
},
suggest: function (text, html) {
if (text.split(' ').length > 1)
return [];
if (noun_type_blip_contact.contactList == null) {
getBlipContacts(noun_type_blip_contact.callback);
return [];
}
var suggestions = [];
for (var c in noun_type_blip_contact.contactList) {
if (new RegExp("^"+text, "i").test(noun_type_blip_contact.contactList[c])) {
suggestions.push(CmdUtils.makeSugg(noun_type_blip_contact.contactList[c]));
}
}
suggestions = suggestions.splice(0, 5);
suggestions.push(CmdUtils.makeSugg(text));
return suggestions;
}
};
const BLIP_STATUS_MAXLEN = 160;
CmdUtils.CreateCommand({
name: "blipnij",
takes: {status: noun_arb_text},
// czekamy az bedzie mozna bardziej opisac przyjmowane parametry
// modifiers: {do: noun_type_blip_contact, tylkodo: noun_type_blip_contact},
modifiers: {do: noun_type_blip_contact},
icon: "http://static0.blip.pl/favicon.gif",
homepage: "http://x4.exroot.org/ubi.html",
author: {
name: "Paweł 'X4lldux' Drygas",
homepage: "http://flaker.pl/X4lldux",
email: "x4lldux@jasbter.pl"
},
license: "MPL",
description: "Ustawia twój status na Blipie.",
help: "Będziesz potrzebować <a href=\"http://blip.pl\">konta na Blipie</a>. Jeśli nie jesteś zalogowny będziesz musiał się zalogować.",
preview: function(previewBlock, statusText, modifiers) {
var truncateTemplate = "<br />Pozostałe <b>${truncate}</b> " +
"znaków zostanie obciętych!";
var previewTemplate = null;
var previewData = null;
if(typeof modifiers.do == 'object') {
previewTemplate = "Blipnij wiadomość do ${to}: <br/>" +
"<b>${status}</b><br /><br />" +
"Pozostało znaków: <b>${chars}</b>";
previewData = {
status: statusText.text,
chars: BLIP_STATUS_MAXLEN - statusText.text.length,
to: modifiers.do.text
};
// } else if(typeof modifiers.tylkodo == 'object') {
// previewTemplate = "Blipnij prywatną wiadomość do ${to}: <br/>" +
// "<b>${status}</b><br /><br />" +
// "Pozostało znaków: <b>${chars}</b>";
// previewData = {
// status: statusText.text,
// chars: BLIP_STATUS_MAXLEN - statusText.text.length,
// to: modifiers.tylkodo.text
// };
} else {
previewTemplate = "Blipnij nowy status: <br/>" +
"<b>${status}</b><br /><br />" +
"Pozostało znaków: <b>${chars}</b>";
previewData = {
status: statusText.text,
chars: BLIP_STATUS_MAXLEN - statusText.text.length
};
}
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
if(previewData.chars < 0) {
var truncateData = {
truncate: 0 - previewData.chars
};
previewHTML += CmdUtils.renderTemplate(truncateTemplate, truncateData);
}
previewBlock.innerHTML = previewHTML;
},
execute: function(statusText, modifiers) {
if(statusText.text.length < 1) {
displayMessage("Blip potrzebuje żebyś coś wpisał zanim wyślesz.");
return;
}
var dm = false; // private/directed message
var updateUrl = "http://api.blip.pl/updates";
var updateParams = "update[body]=";
if(typeof modifiers.do == 'object') {
updateParams += ">"+modifiers.do.text;
dm = true;
// } else if(typeof modifiers.tylkodo == 'object') {
// updateParams += ">>"+modifiers.tylkodo.text;
// dm = true;
}
updateParams += " "+statusText.text.slice(0, BLIP_STATUS_MAXLEN);
jQuery.ajax({
type: "POST",
url: updateUrl,
data: updateParams,
dataType: "json",
error: function() {
displayMessage("BLIP: błąd - statusu nie ustawiono");
},
success: function() {
if(dm)
displayMessage("BLIP: Wiadomość wysłano");
else
displayMessage("BLIP: Status ustawiono");
}
});
}
});
makeSearchCommand({
name: "blip-search",
url: "http://blipscan.pl/s?q={QUERY}",
icon: "http://blipscan.pl/favicon.gif",
description: "Przeszukuje zasoby Blipa.",
homepage: "http://x4.exroot.org/ubi.html",
author: {
name: "Paweł 'X4lldux' Drygas",
homepage: "http://flaker.pl/X4lldux",
email: "x4lldux@jasbter.pl"
},
license: "MPL",
preview: function(pblock, directObject) {
var searchTerm = directObject.text;
var pTemplate = "Przeszukuje Blipa w poszukiwaniu <b>${query}</b>...";
var pData = {query: searchTerm};
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
var url = "http://blipscan.pl/s?q="+searchTerm;
jQuery.get(url, function(data) {
var $=window.jQuery;
var resp = $(".result:lt(5)", data);
resp=resp.remove("script");
if(resp.length == 0)
return;
$(pblock).append(resp);
}, "html");
}
});
CmdUtils.CreateCommand({
name: "last-blip",
icon: "http://static0.blip.pl/favicon.gif",
homepage: "http://x4.exroot.org/ubi.html",
author: {
name: "Paweł 'X4lldux' Drygas",
homepage: "http://flaker.pl/X4lldux",
email: "x4lldux@jasbter.pl"
},
license: "MPL",
description: "Pokazuje ostatni status.",
help: "Będziesz potrzebować <a href=\"http://blip.pl\">konta na Blipie</a>. Jeśli nie jesteś zalogowny będziesz musiał się zalogować.",
preview: function(previewBlock, statusText) {
var previewTemplate = null;
var previewData = null
var url = "http://api.blip.pl/dashboard?include=pictures,user,recipient,user[avatar],recipient[avatar]&limit=50";
var me = getBlipLoggedUser();
var status = {};
previewTemplate = "Wyświetla ostatnią status/wiadomość z twojego kokpitu...";
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
previewBlock.innerHTML = previewHTML;
jQuery.getJSON(url, function(data) {
for each(var o in data) {
if(o.user_path != me.path) {
status = o;
break;
}
}
if(status.type == "Status") {
previewTemplate = "<b>${user}</b>: ${body}";
previewData = {
body: status.body,
user: status.user_path.replace("/users/", ""),
};
} else if(status.type == "DirectedMessage") {
previewTemplate = "<b>${user} > ${recipient}</b>: ${body}";
previewData = {
body: status.body,
user: status.user_path.replace("/users/", ""),
recipient: status.recipient_path.replace("/users/", ""),
};
} else if(status.type == "PrivateMessage") {
previewTemplate = "<b>${user} >> ${recipient}</b>: ${body}";
previewData = {
body: status.body,
user: status.user_path.replace("/users/", ""),
recipient: status.recipient_path.replace("/users/", ""),
};
}
if(status.pictures_path) {
jQuery.getJSON("http://api.blip.pl"+status.pictures_path, function(data) {
previewTemplate+="<br /><img src=\""+data[0].url+"\">";
previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
jQuery(previewBlock).html(previewHTML);
});
previewHTML = CmdUtils.renderTemplate(previewTemplate+"<br />[foto]", previewData);
jQuery(previewBlock).html(previewHTML);
return;
}
previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
jQuery(previewBlock).html(previewHTML);
});
},
execute: function(statusText) {
var url = "http://api.blip.pl/dashboard?limit=50";
var status = {};
var me = getBlipLoggedUser();
jQuery.getJSON(url, function(data) {
for each(var o in data) {
if(o.user_path != me.path) {
status = o;
break;
}
}
Utils.openUrlInBrowser("http://blip.pl/s/"+status.id);
});
}
});
// test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment