Open nwiek opened 4 months ago
I havent tested it yet on chrome, i am using firefox 126.0.1 the button should appear as an element fixed to the bottom left corner of the viewport, but i know that rarely the "download invoice" buttons for each part / the "download all invoices" button don't appear, and i need to refresh the page. still not sure what is causing this issue.
Hi Peter,
Thanks or your reply. I installed FireFox and indeed see the download button.
However the files downloaded are not PDF document but HTML and JScript files. Am I doing something wrong?
Seems to be missing the invoiceId, I fixxed it by replacing the download function with this:
function downloadInvoice(orderId, name) {
GM_xmlhttpRequest({
responseType: 'json',
method: "GET",
url: `https://trade.aliexpress.com/ajax/invoice/queryInvoiceIdAjax.htm?orderIds=${orderId}`,
onload: function (response) {
const invoiceId = response.response[0];
const sanitizedFileName = sanitizeFileName(name);
const url = `https://trade.aliexpress.com/ajax/invoice/invoiceExportAjax.htm?orderId=${orderId}&invoiceId=${invoiceId}&name=${sanitizedFileName}`;
console.log(url);
GM_download({
url: url,
name: `invoice_${orderId}_${sanitizedFileName}.pdf`,
onerror: function (error) {
console.error("Error downloading:", error);
},
});
},
onerror: function (error) {
console.error("Error downloading:", error);
},
});
}
You also need to add this to the header:
// @grant GM_xmlhttpRequest
I'm not sure if there may be cases when the additional request returns an array with multiple invoiceIds – won't work with this code. For my testing, using only the index 0 was enough.
I'm unable to find the download all invoices button. Tampermonkey says script is running.
Please let me know where I should find the button in more detail.