const UNTINY_PRE_URI = "http://untiny.alzaid.ws//api/1.0/extract/?url="; 
const UNTINY_SUFF_URI = "&format=xml"; 
var doc = Application.activeWindow.activeTab.document;
CmdUtils.CreateCommand({
  name: "untiny",
  homepage: "http://www.da-crystal.net",
  author: { name: "da-crystal"},
  locale: "en-US",
  license: "MPL",
  description: "Use Untiny API(www.Untiny.me). Extract the orignal urls from tiny urls. Untiny supports several tiny url services like tinyurl.com, tiny.pl and many more.",
  help: "Untiny with Ubiquity!",
  icon: "http://untiny.alzaid.ws/images/untiny_logo_64.png",

  takes: {"url": noun_arb_text},
  preview: function( pblock, tinyURL) {
    var baseUrl = UNTINY_PRE_URI+ tinyURL.text+ UNTINY_SUFF_URI;
    pblock.innerHTML = "Untiny...";
    jQuery.get( baseUrl, null,function(data){
        var el = jQuery(data).find("response");
        el = el.find("org_url").text();
        if(el.length>0)
          pblock.innerHTML = "Original URL:<span style=\"color:yellow\">"+el+"</span>";
        else
          pblock.innerHTML = "<span style=\"color:red\">Is that a tiny Url?!</span>";

    },"xml");
  },

  execute: function( tinyURL) {
    var baseUrl = UNTINY_PRE_URI+ tinyURL.text+ UNTINY_SUFF_URI;
    jQuery.get( baseUrl, null,function(data){
        var el = jQuery(data).find("response");
        var link = el.find("org_url").text();
        if(link.length>0)
            doc.location.href = link;
    },"xml");
  }
})