// IS.GD COMMANDS FOR UBIQUITY
//
// The first function provides copy-to-clipboard functionality in Firefox 3 and is
// needed for the second and third functions to operate properly.
//
// The second function takes a selected url (for example in an email or text box)
// and replaces it with a compressed is.gd url and copies the compressed url to
// your clipboard
//
// The third function takes the page url that you're currently on and compresses it
// using is.gd then copies the compressed url to your clipboard.
//
// Simply copy and paste the following code into your Ubiquity command-editor!
//
// ~Tomas (http://theclosetentrepreneur.com)
function copyToClipboard(str){
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(str);
}
CmdUtils.CreateCommand({
name: "is-gd replace",
icon: "http://is.gd/favicon.ico",
takes: {"url to shorten": noun_arb_text},
preview: "Replaces the selected URL with an is.gd URL and copies it to the clipboard.",
description: "Replaces the selected URL with an is.gd url",
execute: function( urlToShorten ) {
var baseUrl = "http://is.gd/api.php";
var params = {longurl: urlToShorten.text};
jQuery.get( baseUrl, params, function( isGd ) {
CmdUtils.setSelection( isGd );
copyToClipboard( isGd );
})
}
});
CmdUtils.CreateCommand({
name: "is-gd create",
icon: "http://is.gd/favicon.ico",
description: "Takes the current page URL and copies the is.gd url to your clipboard.",
takes: {"url": noun_arb_text},
modifiers: {},
preview: function( pblock ) {
var document = context.focusedWindow.document;
pageurl=document.location;
var html='Compress a long url to an is.gd url';
jQuery.ajax({
type: 'GET',
url: 'http://is.gd/api.php',
data: {longurl: pageurl},
dataType: 'text',
error: function(){
pblock.innerHTML='WARNING: service is not available. Try later';
},
success: function (data){
html+=' ';
html+='';
copyToClipboard(data);
html+=' The short link is in your clipboard, paste it where you want and enjoy!';
pblock.innerHTML=html;
}
});
}
});