Skip to content

Instantly share code, notes, and snippets.

@ecarnevale
Created October 12, 2009 14:39
Show Gist options
  • Select an option

  • Save ecarnevale/208462 to your computer and use it in GitHub Desktop.

Select an option

Save ecarnevale/208462 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
names: ["svel.to", "svel to", "svelto", "short"],
icon: 'http://mikamai.com/favicon-black.png',
description: "Shortens URLs with http://svel.to",
help: "Type svel.to followed by the URL you want to shorten",
author: "Emanuel Carnevale",
license: "GPL",
homepage: "http://emanuelcarnevale.com",
arguments: [{role: "object",
nountype: noun_type_url,
label: "url to shorten"}],
preview: function preview(pblock, args) {
pblock.innerHTML = "Replaces <b>" + args.object.text + "</b> with ...";
},
execute: function execute(args) {
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Accept","application/json");
xhrObj.setRequestHeader("Content-Type","application/json");
},
contentType: "application/json",
type: "POST",
url: "http://svel.to/links",
data: {link: args.object.text},
processData: false,
success: function(json){ //callback
json = Utils.json.decode(json);
CmdUtils.setSelection( json.url );
CmdUtils.copyToClipboard( json.url );
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment