Skip to content

Instantly share code, notes, and snippets.

@ricardopontes
Created February 21, 2011 12:27
Show Gist options
  • Select an option

  • Save ricardopontes/836986 to your computer and use it in GitHub Desktop.

Select an option

Save ricardopontes/836986 to your computer and use it in GitHub Desktop.
Comando do add-on Ubiquity (Firefox) para o encurtador toma.ai
/*
Criado por Ricardo Pontes (@ricardopontes)
Email: [email protected]
*/
CmdUtils.CreateCommand({
names: ["tomai", "toma.ai"],
arguments: noun_type_url,
icon: 'http://toma.ai/favicon.ico',
description: ("Encurte sua URL com o toma.ai."),
preview: function(pblock, {object: {text}}){
if (!text) {
pblock.innerHTML = this.description;
return;
}
var shortener = this;
pblock.innerHTML = _("Encurtando URL...");
CmdUtils.previewGet(pblock, this._api(text), function(tomai) {
if(tomai !== "Error")
pblock.innerHTML = _("Url encurtada <b>${tomai}</b>.",
{tomai:shortener._link(tomai)});
});
},
execute: function(args) {
var shortener = this;
jQuery.get(this._api(args.object.text), function(tomai) {
CmdUtils.setSelection(shortener._link(tomai), {text: tomai});
Utils.clipboard.text = tomai;
});
},
_api: function(url)("http://toma.ai/encurtar.php?return_type=txt&url=" +
encodeURIComponent(url)),
_link: function(url) {
var conteudo = Utils.escapeHtml(url);
return conteudo.link(conteudo);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment