Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ruben-rodriguez/f103ecf7b377c1076ee9812f83aae259 to your computer and use it in GitHub Desktop.
Save ruben-rodriguez/f103ecf7b377c1076ee9812f83aae259 to your computer and use it in GitHub Desktop.
Added product price and amount
// ==UserScript==
// @name Aliexpress
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://trade.aliexpress.com/orderList.htm*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
(function() {
'use strict';
})();
var orders = [];
var reqs = [];
$(".order-item-wraper").each((ind, el)=>{
var products = [];
$(el).find(".order-body").each((i,e)=>{
$(e).find(".product-sets").each((i,e)=>{
let obj = {
title: $(e).find(".product-title").text().trim(),
price: parseFloat($(e).find(".product-amount span:first()").text().trim().slice(1).trim()),
amount: $(e).find(".product-amount span:eq(1)").text().trim().slice(1)
};
products.push(obj);
// console.log(obj);
});
// console.log(products);
});
var hasTracking = $(el).find(".button-logisticsTracking ").length > 0;
let order = {
id: $(el).find(".order-info .first-row .info-body ").text().trim(),
status: $(el).find(".order-status .f-left").text().trim(),
orderPrice: $(el).find(".amount-num").text().trim(),
productPriceAndAmount: $(el).find(".product-right .product-amount").text().trim().replace(/(?:\s\s)/g, ""),
productsNames: products.map((it)=> it.title).join(", "),
orderDate: $(el).find(".order-info .second-row .info-body").text().trim(),
sellerName: $(el).find(".store-info .first-row .info-body").text().trim(),
hasTracking: hasTracking,
products: products,
};
if (hasTracking){
var req = new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url: "https://ilogisticsaddress.aliexpress.com/ajax_logistics_track.htm?orderId=" + order.id + "&callback=test",
onload:(data)=>{
order.tracking = eval(data.responseText).tracking;
order.trackingNumber = order.tracking.map(it=>it.mailNo).join(", ");
resolve(order);
orders.push(order);
},
onerror: () => reject(400)
});
});
reqs.push(req);
} else{
orders.push(order);
}
});
$.when.apply(null, reqs).done(function(){
// console.log(orders);
// console.log(orders.length);
});
//<button id="search-btn" class="ui-button ui-button-primary search-btn" type="button">Search</button>
$('#mybutton').one('click', function(){
var r=$('<input/>').attr({
type: "button",
id: "field",
value: 'LOAD CSV'
});
$("body").append(r);
});
$('<button/>', {
text: "LOAD", //set text 1 to 10
id: 'csvBtn',
click: function () {
$("#csvBtn").text("Loading...");
Promise.all(reqs).then(o =>{
var s = "";// = "id\t trackingNumber\t productsNames\t status\t orderPrice \t productsPrice \t url \n";
orders.forEach(e=> {
console.log(e);
s += e.id + "\t";
s += (e.trackingNumber || ' ') + "\t";
s += e.productsNames + "\t";
s += e.status + "\t";
s += e.orderPrice + "\t";
s += "https://trade.aliexpress.com/order_detail.htm?orderId=" + e.id + "\t";
s += e.orderDate + "\t";
s += e.sellerName + "\t";
s += e.productPriceAndAmount + "\t";
s += "\n";
});
console.log(s);
GM_setClipboard (s);
$("#csvBtn").text("Loaded to clipboard");
});
}
}).appendTo("#appeal-alert");
function test(data){ return data;}
@mrk741
Copy link

mrk741 commented Mar 17, 2018

can you add some more details into this script
Product Properties
Product Id / Product Code
Store name:/Store Code

@techpad-marcb
Copy link

fantastic thank you for the script

@MarbleMad06
Copy link

thank for this fork. how to change the date format to dd/mm/yyyy please ?

@bizrycki
Copy link

Thanks for the code, it's really fantastic, however it stopped working after page 5, I try to load the orders to the clipboard on page 6 and the 'Loading' message doesn't update to "Loaded to Clipboard". Can you advise? Thanks again!

@svencius
Copy link

Could you please provide the code with Contact Name added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment