Skip to content

Instantly share code, notes, and snippets.

@BrunoCaimar
Created September 18, 2009 02:57
Show Gist options
  • Save BrunoCaimar/188850 to your computer and use it in GitHub Desktop.
Save BrunoCaimar/188850 to your computer and use it in GitHub Desktop.
Migre.Me Ubiquity command
CmdUtils.CreateCommand({
names: ["migre", "migreme"],
icon: "http://www.podpods.com.br/favicon.gif",
description: "Migre.ME - Compactar URL",
help: "Migre.ME - Compactar URL <br/> Desenvolvido por <a style='color: blue' href=http://twitter.com/brunocaimar/>Bruno Caimar</a><br/> Versão 0.2.0_20091116",
author: {name: "Bruno Caimar", email: "bruno.caimar@gmail.com"},
license: "MIT",
homepage: "http://ubiquity.brunocaimar.com/",
arguments: [{role: 'object', nountype: noun_arb_text, label: 'URL para compactar'}],
preview: function preview(pblock, args) {
var me = this;
pblock.innerHTML = "<b>Migre.Me</b> - Compactar a URL <b>" + Utils.escapeHtml(args.object.text);
if (Utils.trim(args.object.text) !== "") {
CmdUtils.previewGet(pblock, this._api(args.object.text), function (retorno) {
var _ret = me._tratarRetorno(retorno);
var msg = "";
if (_ret.error === "0") {
msg = "URL Compactada: <b style='color: blue'><a href='" + _ret.migreUrl + "'>" + _ret.migreUrl + "</a></b>";
Utils.clipboard.text = _ret.migreUrl;
} else {
msg = "<b style='color: red'>" + _ret.errorMessage + "</b>";
}
pblock.innerHTML += "<br/>" + msg;
});
}
},
execute: function(args) {
var me = this;
jQuery.get(this._api(args.object.text), function(migreRet) {
var _ret = me._tratarRetorno(migreRet);
CmdUtils.setSelection(me._link(_ret.migreUrl), {text: _ret.migreUrl});
Utils.clipboard.text = _ret.migreUrl;
displayMessage("Migre.ME URL --> " + _ret.migreUrl, this);
});
},
_api: function(url)("http://migre.me/api.xml?url=" +
encodeURIComponent(url)),
_link: function(url) {
var eu = Utils.escapeHtml(url);
return eu; // .link(eu);
},
_tratarRetorno: function(ret) {
var _error = jQuery('error', ret);
var _errorMessage = jQuery('errormessage', ret);
var _migreUrl = jQuery('migre', ret);
return {error: _error.text(), errorMessage: _errorMessage.text(), migreUrl: _migreUrl.text()};
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment