Last active
March 7, 2017 14:20
-
-
Save sharnie/51260f64d789de9813c68270a174f6ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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¤cyCode=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