Skip to content

Instantly share code, notes, and snippets.

@sharnie
Last active March 7, 2017 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharnie/51260f64d789de9813c68270a174f6ba to your computer and use it in GitHub Desktop.
Save sharnie/51260f64d789de9813c68270a174f6ba to your computer and use it in GitHub Desktop.
(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