Skip to content

Instantly share code, notes, and snippets.

@sharnie sharnie/epacket.js
Last active Mar 7, 2017

Embed
What would you like to do?
(function() {
'use strict';
if ( !$('#narrow-form').length ) {
return false;
}
var markup = `
<img src="http://i00.i.aliimg.com/wimg/buyer/single/icon-ems.jpg" style="border: 3px solid #6FFF96; position: absolute; z-index: 0; width: 55px;" />
`;
var BASE_URL = 'http://freight.aliexpress.com/ajaxFreightCalculateService.htm?country=US&count=1&f=d&currencyCode=USD';
var $items = $( '#list-items .list-item, .list-items .list-item' );
$items.each(function( index, item ) {
var $item = $( item );
setTimeout(function() {
if ( $item.attr('qrdata') ) {
var qrdata = $item.attr( 'qrdata' );
$.ajax({
type: 'GET',
dataType: 'jsonp',
url: BASE_URL + '&productid=' + qrdata.split( '|' )[1],
success: function( response ) {
for ( var i = 0; i < response.freight.length; i++ ) {
if ( response.freight[i].companyDisplayName === 'ePacket' ) {
var price = parseFloat( $item.find( '.price .value' ).text().replace( /[^\d.]/gi, '' ) );
price = ( parseFloat(response.freight[i].price) + price ).toFixed(2);
$item.prepend( $(markup) );
$item.prepend( $('<span style="font-size: 21px; position: absolute; right: 172px; z-index: 0; background: #FF6F6F; color: #fff;">$' + price + '</span>') );
}
}
}
});
}
}, 150 + (index * 500) );
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.