Skip to content

Instantly share code, notes, and snippets.

@naixx
Last active November 17, 2023 15:50
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save naixx/9929f308bfc0aac649d7c48c4a510737 to your computer and use it in GitHub Desktop.
Save naixx/9929f308bfc0aac649d7c48c4a510737 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Aliexpress
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://trade.aliexpress.ru/orderList.htm*
// @match https://trade.aliexpress.com/orderList.htm*
// @match https://trade.aliexpress.ru/order_list.htm*
// @match https://trade.aliexpress.com/order_list.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(),
date: Date.parse($(el).find(".order-info .second-row .info-body ").text().trim()),
status: $(el).find(".order-status .f-left").text().trim(),
orderPrice: $(el).find(".amount-num").text().trim(),
productsPrice: products.map((it)=> it.price).reduce((a, b) => a + b, 0),
productsNames: products.map((it)=> it.title).join(", "),
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)=>{
console.log(eval(data.responseText));
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 = "";// = "date\t trackingNumber\t productsNames\t status\t orderPrice \t productsPrice \t url \n";
var preview = "<table>";
orders.sort((a, b)=> b.date - a.date).forEach(e=> {
console.log(e);
var d = new Date(e.date);
var date = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate();
s += date + "\t";
s += (e.trackingNumber || ' ') + "\t";
s += e.productsNames + "\t";
s += e.status + "\t";
s += e.orderPrice + "\t";
s += e.productsPrice + "\t";
s += "https://trade.aliexpress.com/order_detail.htm?orderId=" + e.id;
s += "\n";
preview += "<tr>";
preview += "<td>" + date + "</td>";
preview += "<td>" +(e.trackingNumber || ' ') + "</td>";
preview += "<td style='width: 25%'>" +e.productsNames + "</td>";
preview += "<td>" + e.status + "</td>";
preview += "<td>" +e.orderPrice + "</td>";
preview += "<td>" + e.productsPrice + "</td>";
var url = "https://trade.aliexpress.com/order_detail.htm?orderId=" + e.id;
preview += "<td><a href='" + url + "'>" + url + "</a></td>";
preview += "</tr>";
});
preview += "</table>";
console.log(s);
GM_setClipboard (s);
$("#csvBtn").text("Loaded to clipboard");
$("#preview").remove();
$(preview).attr('id', 'preview').css({"overflow-x": "scroll"}).appendTo("#appeal-alert");
});
}
}).appendTo("#appeal-alert");
$('<button/>', {
text: "Show/hide preview",
id: 'togglePreview',
click: function () {
$("#preview").toggle();
}}).appendTo("#appeal-alert");
function test(data){ return data;}
@f-alex
Copy link

f-alex commented Aug 19, 2018

@naixx
Thanks, I made forked script that export items instead orders

@jasperdev101
Copy link

by chance, have you had any updates to the script? It worked for the first 6 pages, and now, it is stuck on saying "loading" everytime I click load

@FPLTN
Copy link

FPLTN commented Nov 16, 2018

Super cool idea! I'm new here and not sure how to really get it working. In fact, this is my first ever time working with a script. When pasting into notepad, its kinda all over the place, is there any way I can collate this into an Excel spreadsheet? The purpose of this is to add up the exact amount of money paid every month or so for our P&L

Best

@Oskimark
Copy link

just what i was looking for. simple. i dont know why but when i copy the code from above it doesnt work, just keep "loading".
the i download the zip and copy from there and it works.

@wlei6277
Copy link

wlei6277 commented Jul 1, 2019

Hi all I forked this script to collect data on each product on the order page. Have also done a rough calculation of the delivery price, and tax paid per order (calculation is imperfect but works for most cases). Also included a Aus to USD forex rate for each order. Can be found at the following link

https://gist.github.com/wlei6277/dfe13af8bf77c4cc7dee23fd981abe96

@naixx
Copy link
Author

naixx commented Jul 1, 2019

@wlei6277 great job!

@dragoncity17
Copy link

dragoncity17 commented Mar 14, 2020

Great good job !

  • is it possible to have the oldest to the newest order ?

  • and for the "date" convert like this :
    03:14 Mar. 14 2020 >> 14/03/2020

Thank you in advance,

Regards

@naixx
Copy link
Author

naixx commented Mar 15, 2020

@dragoncity17 It is out of the scope of this script

@dragoncity17
Copy link

Damn because your script is really great, I just wanted to add these 2 little things.

@dragoncity17
Copy link

Hi all I forked this script to collect data on each product on the order page. Have also done a rough calculation of the delivery price, and tax paid per order (calculation is imperfect but works for most cases). Also included a Aus to USD forex rate for each order. Can be found at the following link

https://gist.github.com/wlei6277/dfe13af8bf77c4cc7dee23fd981abe96

I tested,and it's sorted by date, how can I just add this function in the script so that it's sorted by date?

Just that, nothing more :)

@dragoncity17
Copy link

dragoncity17 commented Mar 24, 2020

So I made it by "mixing" your two scripts (thanks again for your scripts) :

https://gist.github.com/dragoncity17/ec236643832f099736e9f41da88a5870

I now have the commands in order.

BUT, one thing I didn't manage to include is the tracking number.

When I add doesn't work... o_O

If you have any idea how to add it, thanks in advance :)

@tonyboom3d
Copy link

So I made it by "mixing" your two scripts (thanks again for your scripts) :

https://gist.github.com/dragoncity17/ec236643832f099736e9f41da88a5870

I now have the commands in order.

BUT, one thing I didn't manage to include is the tracking number.

When I add doesn't work... o_O

If you have any idea how to add it, thanks in advance :)

NICE thx! is it exporting also tracking numbers and the phone numbers in the order ?

@dragoncity17
Copy link

"BUT, one thing I didn't manage to include is the tracking number."...

@tonyboom3d
Copy link

tonyboom3d commented Apr 12, 2020

"BUT, one thing I didn't manage to include is the tracking number."...

Ohh missed this part sry. is there anyway it can grab the tracking number ?

@dragoncity17
Copy link

I tested but I didn't make it.

So maybe the creator can just watch for tracking, I don't think it's complicated, just that I'm not an expert :)

@kluszczyn
Copy link

So I made it by "mixing" your two scripts (thanks again for your scripts) :

https://gist.github.com/dragoncity17/ec236643832f099736e9f41da88a5870

I now have the commands in order.

BUT, one thing I didn't manage to include is the tracking number.

When I add doesn't work... o_O

If you have any idea how to add it, thanks in advance :)

I've made remix based on your remix :)
I've added "Product description" and "Product Action" to the report and formatted order date. Export looks like this:

orderID orderDate orderShipment orderAction orderDesc orderProperties orderQty orderLineCost orderCost orderShop
30x3xx55xx60xx19 2020-03-30 21:50:00 Awaiting delivery Open Dispute 10Pcs Mini Small N35 Round Magnet 5x1 6x3 8x3 10x1 10x2 12x2 mm Neodymium Magnet Permanent NdFeB Super Strong Powerful Magnets 5x1mm 1 0.48 $ 2.78 Ace Wong's store

Fork available here: AliExpress Orders Lines

@dragoncity17
Copy link

dragoncity17 commented Apr 13, 2020

Cool :)

But miss "track number" ^^

I know it's this code,but I don't know how add :

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(),
productsPrice: products.map((it)=> it.price).reduce((a, b) => a + b, 0),
productsNames: products.map((it)=> it.title).join(", "),

    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);
}

@ohuf
Copy link

ohuf commented Apr 30, 2020

I did a fork that works on a product line basis, converts the prices to Euro and grabs the product properties (size, color, ...) as well.
find it here: https://gist.github.com/ohuf/41144630af44533eab36b52ec3381292

(Kudos to wlei6277)

Edit: Oh, and mine also deals with converting Euro based decimal points. Background: The Euro prices in AliExpress are given (correctly so) with a decimal "comma" instead of a decimal point, which would lead to the cents being cut off in the original scripts!

@ohuf
Copy link

ohuf commented Apr 30, 2020

productsPrice - What mean this number?
Orderpage- Okay

On my export i have this on productsPrice

2
1

Are these by any chance products where the currency is not USD (e.g. Euro)? In that case AliExpress displays the decimal "comma" instead of the decimal point. With this script the cents are being cut-off on these prices.

  1. You can "normalize" the numbers using .replace(',' , '.') in the relevant places
  2. I forked a fork of the script here

@poldim
Copy link

poldim commented Apr 30, 2020

I combined the tracking tampermonkey script and the order detail one into one unified script. I will preface this that I haven't done any coding in 15 years, so it's mostly trial and error until I get it to work. There are probably many better ways to do this.

  • Added tracking to the webpage (not export, if someone can fix this, be my guest)
  • Added a button to copy the column header to the clipboard
  • Rearranged columns to move less important columns further to the right

https://gist.github.com/poldim/96af32979a838dbb4816bd3352152859

@dragoncity17
Copy link

dragoncity17 commented Apr 30, 2020

Great "poldim"

I like : Added tracking to the webpage

But miss export yes... :(

I saw you added export "Item Picture URL",do you know how to see in "Google Sheets" ?

It's OK :)

@dragoncity17
Copy link

dragoncity17 commented Apr 30, 2020

I finished ^^ ! (I am not an DEV...difficult for me !)
Miss again tracking...I don't know why because I added like the first script o_O

So I used part of your script "poldim".

And I added :

  • LINK directly on ID.
  • LINK directly on image product.

alt text

I updated :
https://gist.github.com/dragoncity17/ec236643832f099736e9f41da88a5870

If someone can see why tracking doesn't work... :)

@naixx
Copy link
Author

naixx commented Jun 28, 2021

Added preview

@gitcnd
Copy link

gitcnd commented Oct 22, 2021

Awesome script!!

Note that it requires this to function:
https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo/related

Also note that you can right-click on the "10 items per page" dropdown, and "inspect" it, and change it to 100 (or whatever), then when you click that, you can load and extract more than 10/20/30 items in one go!

@Haldyz
Copy link

Haldyz commented Nov 25, 2021

hi. is it still working? when I click on load button, it stuck - i was waiting for 10mins

@naixx
Copy link
Author

naixx commented Nov 25, 2021

Yep, still works for me

@S1M34
Copy link

S1M34 commented Feb 6, 2022

Hello guys did you see order page have updated its change look and apirience i supose this script is dont work any more . Did some one make updated ?

@dragoncity17
Copy link

Same problem, someone update ? Thanks

@Grupoecommedia
Copy link

Same here, since the new Aliexpress interface there is no way to export the orders to csv. Does someone found a way to do it?

Thank you very much

@Grupoecommedia
Copy link

Same problem, someone update ? Thanks

Hello, have you been able to solve it?

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