Skip to content

Instantly share code, notes, and snippets.

@danilopopeye
Created October 2, 2008 16:55
Show Gist options
  • Select an option

  • Save danilopopeye/14396 to your computer and use it in GitHub Desktop.

Select an option

Save danilopopeye/14396 to your computer and use it in GitHub Desktop.
Verifica o <b>status</b> do seu pacote SEDEX! :)
CmdUtils.CreateCommand({
name: "sedex",
homepage: "http://ubiquity.danilosousa.net/",
author: { name: "Danilo Sousa", email: "eu@danilosousa.net" },
takes: { "code": noun_arb_text },
icon: "chrome://ubiquity/content/icons/map.png",
description: "Verifica o <b>status</b> do seu pacote SEDEX! :)",
preview: function( previewBlock, directObject ) {
previewBlock.innerHTML = "Carregando...";
var doc = context.focusedWindow.document;
var code = jQuery.trim( directObject.text );
if( code == "" ){
previewBlock.innerHTML = "Digite um código de rastreamento.";
return false;
} else if( code.length != 13 ){
previewBlock.innerHTML = "Código de rastreamento inválido.";
return false;
}
var url = "http://websro.correios.com.br/sro_bin/txect01$.QueryList";
var params = {
"P_LINGUA": "001",
"P_TIPO": "001",
"P_COD_UNI": code
};
jQuery.get( url, params, function( data ) {
previewBlock.innerHTML = '<div id="sedexHTML" style="display:none">' + data + '</div>';
var sedexHTML = previewBlock.firstChild;
var form = sedexHTML.lastChild;
for( i in form.childNodes ){
if( form.childNodes[i].tagName == "TABLE" ){
var content = form.childNodes[i];
break;
}
}
if( !content ){
previewBlock.innerHTML = form.lastChild.textContent;
} else {
var style = doc.createElement('style');
style.type = 'text/css';
style.innerHTML += 'table tbody tr:first-child td font { color: white; font-weight: bold; }';
style.innerHTML += 'table tbody td { color: white; }';
style.innerHTML += '';
style.innerHTML += '';
style.innerHTML += '';
previewBlock.innerHTML = "";
previewBlock.appendChild( style );
previewBlock.appendChild( content );
}
});
},
execute:function(directObj) {
var code = jQuery.trim( directObj.text );
Utils.openUrlInBrowser( 'http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' + code );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment