Created
June 28, 2020 16:04
-
-
Save takashiski/fffec713e05c04d4f8e9d3704a3de5a7 to your computer and use it in GitHub Desktop.
aliexpressの注文一覧画面から表示されてる注文すべての追跡番号を含んだ17trackのURLを取得するユーザースクリプト
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 Aliexpress17trackerURLGenerator | |
// @namespace http://takashiski.hatenablog.com/ | |
// @version 0.1 | |
// @description generate URL aliexpress order list to 17Track URL. | |
// @author takashiski | |
// @match https://trade.aliexpress.com/orderList.htm* | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let url="https://t.17track.net/ja#nums="; | |
const orderURL="https://trade.aliexpress.com/order_detail.htm?orderId="; | |
let domparser=new DOMParser(); | |
function getLogisticsNumber(orderNumber) | |
{ | |
return new Promise((resolve)=>{ | |
GM_xmlhttpRequest ( { | |
method: "GET", | |
url: orderURL+orderNumber, | |
responseType: "document", | |
onload: function(res) | |
{ | |
let results=[]; | |
let html_text=res.responseText; | |
let doc=domparser.parseFromString(html_text,"text/html"); | |
let nums=doc.querySelectorAll("div.logistics-num"); | |
for(let i=0;i<nums.length;i+=1) | |
{ | |
let num=nums[i].textContent.trim(); | |
results.push(num); | |
} | |
resolve(results); | |
} | |
} ); | |
}); | |
} | |
window.addEventListener("load",function(){ | |
let results=[]; | |
let orders=document.querySelectorAll("tr.order-head>td.order-info>p.first-row>span.info-body") | |
let tasks=[]; | |
for(let i=0;i<orders.length;i+=1) | |
{ | |
let orderNumber=orders[i].textContent; | |
//console.log(orderNumber); | |
tasks.push(getLogisticsNumber(orderNumber)); | |
} | |
Promise.all(tasks).then(results=>{ | |
//console.log(results); | |
for(let i=0;i<results.length;i+=1) | |
{ | |
url+=results[i]+","; | |
} | |
url=url.substr(0,url.length-1); | |
console.log(url); | |
}); | |
},false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment