-
-
Save sleemanj/95035bf2c0141ac72420 to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name Return the Quantity Search, Show Per Piece Pricing | |
// @namespace https://gist.github.com/sleemanj/95035bf2c0141ac72420 | |
// @updateURL https://gist.github.com/sleemanj/95035bf2c0141ac72420/raw/aliexpress-qty-search-fix.js | |
// @downloadURL https://gist.github.com/sleemanj/95035bf2c0141ac72420/raw/aliexpress-qty-search-fix.js | |
// @version 1.1 | |
// @description Put the quantity search fields back into the search interface on Aliexpress when they are not present and add a per-piece pricing when possible on the listing pages. | |
// @author James Sleeman | |
// @match *://*.aliexpress.com/* | |
// @exclude *://trade.aliexpress.com/orderList.htm* | |
// @grant GM_addStyle | |
// ==/UserScript== | |
(function(){ | |
if(document.getElementById('filter-quantity-c')) return; | |
if(!document.getElementById('filter')) return; | |
var d = document.createElement('div'); | |
d.innerHTML = '<div class="filter-quantity-c" data-widget-cid="widget-25" style="-webkit-user-select: text;">' + | |
'<span id="filter-quantity-c" style="-webkit-user-select: text;"><span class="ui-label">Quantity:</span>' + | |
' <input class="ui-textfield ui-textfield-system" value="" autocomplete="off" id="filter-quantity-from" name="minQuantity" tabindex="22" style="-webkit-user-select: text;"> ' + | |
' <span>-</span> ' + | |
' <input class="ui-textfield ui-textfield-system" value="" autocomplete="off" id="filter-quantity-to" name="maxQuantity" tabindex="23">' + | |
'<input type="submit" value="OK" />' + | |
' </span> ' + | |
'</div>'; | |
document.getElementById('filter').appendChild(d); | |
if(document.location.search.match(/minQuantity=([0-9]+)/)) | |
{ | |
document.getElementById('filter-quantity-from').value = RegExp.$1; | |
} | |
if(document.location.search.match(/maxQuantity=([0-9]+)/)) | |
{ | |
document.getElementById('filter-quantity-to').value = RegExp.$1; | |
} | |
// Display per piece price | |
var items = document.getElementsByClassName('list-item'); | |
console.log('Found ' + items.length + ' Items'); | |
for(var x = 0; x < items.length; x++) | |
{ | |
var PerLot = 1; | |
if(items[x].getElementsByClassName('min-order').length) | |
{ | |
PerLot = parseInt(items[x].getElementsByClassName('min-order')[0].innerHTML.replace(/ pieces.*lot/,'').replace(/\s/g,'')); | |
} | |
else if(items[x].getElementsByClassName('history-item product').length && items[x].getElementsByClassName('history-item product')[0].title.match(/([^0-9]|^)([0-9]+)\s*pcs/i)) | |
{ | |
PerLot = RegExp.$2; | |
} | |
if(PerLot > 1) | |
{ | |
var PriceLot = items[x].getElementsByClassName('price')[0].getElementsByClassName('value')[0].innerHTML.replace(/[^0-9.]/g, ''); | |
var ShippingPriceLot = 0; | |
if(items[x].getElementsByClassName('pnl-shipping').length) | |
{ | |
ShippingPriceLot = parseFloat(items[x].getElementsByClassName('pnl-shipping')[0].getElementsByClassName('value')[0].innerHTML.replace(/[^0-9.]/g, '')); | |
} | |
var NewSpan = document.createElement('div'); | |
NewSpan.style.fontWeight = 'bold'; | |
NewSpan.style.fontSize = 'larger'; | |
NewSpan.innerHTML = '( ' + ((parseFloat(PriceLot)+ShippingPriceLot)/parseInt(PerLot)).toFixed(3) + ' / Piece' + ( items[x].getElementsByClassName('min-order').length ? ' ' : '? ') + (ShippingPriceLot ? ' inc Shipping ':'') + ')'; | |
items[x].getElementsByClassName('price-m')[0].appendChild(NewSpan); | |
} | |
} | |
})(); |
Hello!
First, thanks for Your efforts! But, I don't know if I missed something during import or what happened, but Your script does nothing in my current setup - Tampermonkey reports that "No script is running", even though im browsing on aliexpress's search page... :( So, is this script outdated and its normal, or did i miss some settings instead of importing it with defaults?
Best regards,
Peter
Hey! I've got a project that returns a lot of the Search functionality back to AliExpress . It is a seperate site and I perform the search on our databases so that allows me to add more features. I have Quantity Search, Unit Price Display, and Shipping Type right now but I will be adding lots more 😃 , It's free to use!
Aliseeks - www.aliseeks.com
There is also an API which I can provide access to, just contact me for now if you want access.
Is it possible for you to add a price per piece check box into this great userscript? The search url parameter is &isUnitPrice=y (y or n for yes and no)