RASG / myDX_BR

// ==UserScript==
// @name           myDX_BR
// @namespace      http://stackoverflow.com/users/982924/rasg
// @author         RASG
// @version        2012.06.15
// @description    [EN] DealExtreme script to check the tracking number on the brazilian post office. [PT] Script para o DealExtreme que mostra o rastreio da encomenda direto na pagina, sem precisar ir no site do correio. 
// @icon           https://my.dx.com/favicon.ico
// @require        http://code.jquery.com/jquery.min.js
// @include        http://my.dealextreme.com/*
// @include        https://my.dx.com/*
// @exclude        http://my.dealextreme.com/MyOrders/OrderDetail/*
// @exclude        https://my.dx.com/MyOrders/OrderDetail/*
// ==/UserScript==

/*  
    ----------------------------------------------------------------------------
    METODO DE CARREGAMENTO DO JQUERY (metodo_JQ):
    
    1 = usar o @require do greasemonkey
    2 = carregar o script de jquery.com e inserir na pagina
    
    Tente usar primeiro o metodo padrao (1) que e mais rapido
    Caso o script nao funcione, altere para (2)
    Se ainda assim nao funcionar, informe na pagina do script em userscripts.org
    ----------------------------------------------------------------------------
*/

metodo_JQ(1);

// wait until the DOM is ready
//$(function(){

// wait until the page is actually loaded
$(window).load(function(){
    
    var correio = "http://websro.correios.com.br/sro_bin/txect01$.Inexistente?P_LINGUA=001&P_TIPO=002&P_COD_LIS=";
    var dealext = "http://my.dealextreme.com/MyOrders/OrderTracking/";
    var dxptcom = "https://my.dx.com/MyOrders/OrderTracking/";
    var legacys = "http://www.dealextreme.com/accounts/summaries.dx/OrderNumber.";
    var iconeco = "data:image/gif;base64,R0lGODlhMgAmAOf/AAUxcAAzdwA0eAA3fA00dAA4dwA4fRE2cAI6eQA7fhI3cQU7egA8gAA9exM5bQA9gQc8ewA+ggA/fQA/gwo9fABAfgBBfwBBhQ0+fQBCgABDgQ8/fhk+bBE/fwBEghNAgARFhBtBaRVBgSU/aR1CawdHgCdDZxpFfyBHaihHZSlIZipIZylKYxVNhhZOhytMZTNOYh9SjDNSXx9UiCJWiiNZbyNXiyJYhiRacDxWXixaayZZjSVaiChaj0JYXEFbWCBfk0ZcVSxekkNdWkRdWzV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GBgzx3O2TEiHGORwwOHjx0EOFOhgxlMXIIUREzJoMHdzGWzVjFokNPJeiCKpNxTscHoxpauKsRVCURHS1WcGkhQgQKnUx0vGjRQpIOGx6X1BBRou2JIQq1vJjbAiycF23b7iGloi8sF3Pn0pgUI2+JPVlXKJbSIvCWSTtItBUhVbFlFTxmAH7h4tiOFyxmCEmsWCqPGzIG99uxou+KdnCCAAA7";    
    
   	if (window.location.href.indexOf('my.dx.com') > -1) { 
   		$('.mac_orderbox').append("<div id='divdetalhe'></div>");
   		$('.myorders').append("<div id='divdetalhe'></div>");
   		$('.order_table tr').each(function(){
	        $(this)
	            .find('td:first')
	            .css({'textAlign':'left'})
	            .prepend("<img id='botao_new' src="+iconeco+" style='vertical-align:middle; border:3px solid transparent'>")
	    })
	    dealext = dxptcom;
   	}    

    $("<div id='divtempora'></div>").appendTo('body');	
    $("<div id='divdetalhe'></div>").prependTo('.orders_page:first').hide();
    $("<div id='divcorreio'></div>").appendTo('#divdetalhe');
   	
    $('.orders_middle_kuang:first tr').each(function(){
        $(this)
            .find('td:first')
            .css({'textAlign':'left'})
            .prepend("<img id='botao_new' src="+iconeco+" style='vertical-align:middle; border:3px solid transparent'>")
    })
    $('.orders_middle_kuang:eq(1) tr').each(function(){
        $(this)
            .find('td:first')
            .css({'textAlign':'left'})
            .prepend("<img id='botao_legacy' src="+iconeco+" style='vertical-align:middle; border:3px solid transparent'>")
    })

    $('body')
        .on("click", "#botao_new", function() {
            $(this).animate({opacity : 0.25}, 'slow');
           	$('#divcorreio').html("<img src="+iconelo+">")
            var ordem = $.trim( $(this).next('a').text() )
            $('#divdetalhe').css({'text-align':'center'}).show()
            $('#divtempora').load(dealext+ordem, function() {
                $('#divtempora tr').each(function(){
                    var celula = $(this).find('td').eq(2) 
                    var rastreio = $.trim( $(celula).text() )
                    if ( (rastreio.substr(rastreio.length - 2) == "HK") || (rastreio.substr(rastreio.length - 2) == "CN") ) {
                        conectar('GET', correio+rastreio, resp_correio)	
                    }
                    else { $('#divcorreio').html("") }
                })
            })
            $(this).animate({opacity : 100}, 'slow');
        })
        .on("click", "#botao_legacy", function() {
            $(this).animate({opacity : 0.25}, 'slow');
            $('#divcorreio').html("<img src="+iconelo+">")
            var ordem = $.trim( $(this).next('a').text() )
            $('#divdetalhe').css({'text-align':'center'}).show()
            conectar('GET', legacys+ordem, resp_dxlegacy)
            $(this).animate({opacity : 100}, 'slow');
        })


    function conectar(metodo, endereco, resposta, corpo) {
        callback = function(xhr) { resposta(xhr) };
        GM_xmlhttpRequest({
            "method"	: metodo,
            "url"		: endereco,
            "onerror"	: callback,
            "onload"	: callback,
            "headers"	: {'Content-Type' : 'application/x-www-form-urlencoded'},
            "data"		: corpo
        });
    }

    function resp_dxlegacy(detalhes) {
        var inicio = '>Tracked Air Mail</span><br />';
        var fim = '</span>';
        $('#divtempora').html(detalhes.responseText.split(inicio)[1].split(fim)[0])
        var rastreio = $.trim( $('#divtempora').text() )
        if ( (rastreio.substr(rastreio.length - 2) == "HK") || (rastreio.substr(rastreio.length - 2) == "CN") ) { 
            conectar('GET', correio+rastreio, resp_correio)	
        }
    }

    function resp_correio(detalhes) {
        var inicio = 'entrega.<p>';
        var fim = '<hr width=500';
        $('#divcorreio')
            .html(detalhes.responseText.split(inicio)[1].split(fim)[0])
            .css({'display':'inline-block','background':'#FAFAED'})
    }

});

function metodo_JQ(metodo){
    JQ      	= "http://code.jquery.com/jquery.js";
    JQmin   	= "http://code.jquery.com/jquery.min.js";
    
    if (metodo == 2) {
        var script = document.createElement('script');
            script.src = JQmin;
        var head = document.getElementsByTagName("head")[0];
            (head || document.body).appendChild(script);
    };
};