Created
September 15, 2022 04:12
-
-
Save tvc97/e74e0b660642157546479a296ebdfaa9 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
function getPageTotal(offset = 0) { | |
req = new XMLHttpRequest(); | |
req.open( | |
'GET', | |
`https://shopee.vn/api/v4/order/get_all_order_and_checkout_list?limit=20&offset=${offset}`, | |
false | |
); | |
req.send(); | |
a = JSON.parse(req.responseText); | |
if (a.data.next_offset === -1) return 0; | |
return a.data.order_data.details_list | |
.filter((item) => item.status.status_label.text === 'label_order_completed') | |
.reduce((prev, next) => next.info_card.final_total + prev, 0); | |
} | |
function formatMoney(value) { | |
return Intl.NumberFormat('vi-VN').format(value / 100000); | |
} | |
var currentOffset = 0; | |
var total = 0; | |
while ((pageTotal = getPageTotal(currentOffset)) !== 0) { | |
total += pageTotal; | |
console.log(`Offset ${currentOffset}: ${formatMoney(pageTotal)}`); | |
currentOffset += 20; | |
} | |
console.log(`Total: ${formatMoney(total)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment