Created
October 15, 2019 08:51
-
-
Save madaboutcode/761013086e173146147e70795481d60e 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
// ==UserScript== | |
// @name Aliexpress - Orders to CSV | |
// @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'; | |
})(); | |
function parseOrderDate(d) { | |
return d; | |
} | |
var products = []; | |
$(".order-item-wraper").each((ind, el)=>{ | |
let order = { | |
id: $(el).find(".order-info .first-row .info-body ").text().trim(), | |
orderUrl: el.querySelector(".order-info .first-row .view-detail-link").href, | |
orderStatus: $(el).find(".order-status .f-left").text().trim(), | |
orderPrice: $(el).find(".amount-num").text().trim(), | |
seller: el.querySelector(".store-info .info-body").innerText.trim(), | |
date: parseOrderDate(el.querySelector(".order-info .second-row .info-body").innerText), | |
}; | |
$(el).find(".order-body").each((idxItem,e)=>{ | |
$(e).find(".product-sets").each((i,e)=>{ | |
let prod = { | |
itemNo: idxItem+1, | |
title: $(e).find(".product-title").text().trim(), | |
price: $(e).find(".product-amount span:first()").text().trim(), | |
qty: parseInt(e.querySelectorAll('.product-amount span')[1].innerText.replace('X', '')), | |
url: e.querySelector('.product-title a').href, | |
snapshot: e.querySelector('.product-snapshot a').href | |
}; | |
products.push(Object.assign(prod, order)); | |
}); | |
}); | |
}); | |
console.log(products) | |
$('#mybutton').one('click', function(){ | |
var r=$('<input/>').attr({ | |
type: "button", | |
id: "field", | |
value: 'LOAD CSV' | |
}); | |
$("body").append(r); | |
}); | |
// Order No OrderItem Item ProductURL Order Url Tracking Status Price Qty Order Url Date Seller | |
/* | |
date: "21:28 Oct. 14 2019" | |
id: "8004273528384259" | |
itemNo: 1 | |
orderPrice: "$ 11.99" | |
orderStatus: "Awaiting Shipment" | |
orderUrl: "https://trade.aliexpress.com/order_detail.htm?orderId=8004273528384259" | |
price: 11.99 | |
qty: 1 | |
seller: "Ugreen Official Store" | |
snapshot: "https://www.aliexpress.com/snapshot/0.html?orderId=8004273528394259&productId=32846242794" | |
title: "Ugreen Ethernet Adapter for Chromecast USB 2.0 to RJ45 for Google Chromecast 2 1 Ultra Audio TV Stick Micro USB Network Card" | |
url: "https://www.aliexpress.com/item/Ugreen-Ethernet-Adapter-for-Chromecast-USB-2-0-to-RJ45-for-Google-Chromecast-2-1-Ultra/32846242794.html" | |
*/ | |
let csvProps = ["id", "itemNo", "title", "url", "snapshot", "orderStatus", "price", "qty", "orderUrl", "date", "seller"]; | |
$('<button/>', { | |
text: "LOAD", //set text 1 to 10 | |
id: 'csvBtn', | |
click: function () { | |
$("#csvBtn").text("Loading..."); | |
let rows = []; | |
products.forEach(p=>{ | |
let row = csvProps.map(k=>p[k]); | |
rows.push(row.join('\t')); | |
}); | |
let s = rows.join('\n'); | |
console.log(s); | |
GM_setClipboard (s); | |
$("#csvBtn").text("Loaded to clipboard"); | |
} | |
}).appendTo("#appeal-alert"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment