Created
October 12, 2009 14:39
-
-
Save ecarnevale/208462 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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