Skip to content

Instantly share code, notes, and snippets.

@vikbez
Created July 19, 2019 19:06
Show Gist options
  • Save vikbez/7213dbebd83a360b1ea1256e64710142 to your computer and use it in GitHub Desktop.
Save vikbez/7213dbebd83a360b1ea1256e64710142 to your computer and use it in GitHub Desktop.
Aliexpress display price per unit with shipping (greasemonkey)
// ==UserScript==
// @name Aliexpress Price per item with shipping
// @namespace http://tampermonkey.net/
// @version 2.0
// @description try to take over the world!
// @author vik
// @match https://www.aliexpress.com/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
'use strict';
$(document).ready(function() {
$('head').append("<style>.tpz { color:#0b0; font-size: 14px; font-weight: 700;}</style>");
function checkPrices() {
$('.list-item').each(function (idx, item) {
// ignore done
if ($(item).hasClass('tpz-done')) { return; }
var val = $(item).find('span.price-current').text();
var qty = $(item).find('span.price-unit').text();
var ship = $(item).find('span.shipping-value').text();
if (val.indexOf('-') > 0) {
val = val.split('-')[0];
}
val = val.replace(/[^0-9,]/g, '').replace(',', '.');
qty = qty.replace(/[^0-9,]/g, '').replace(',', '.');
ship = ship.replace(/[^0-9,]/g, '').replace(',', '.');
val = parseFloat(val);
qty = parseFloat(qty);
ship = parseFloat(ship);
val = isNaN(val) ? 0 : val;
qty = isNaN(qty) ? 1 : qty;
ship = isNaN(ship) ? 0 : ship;
var new_e = ((val + ship) / qty);
$(item).find('div.item-price-wrap').after('<b class="tpz">Per unit: ' + new_e.toFixed(3) + '</b>');
$(item).addClass('tpz-done');
//console.log('VAL:', val);
//console.log('QTY:', qty);
//console.log('SHIP:', ship);
});
}
checkPrices();
setInterval(checkPrices, 2000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment