Skip to content

Instantly share code, notes, and snippets.

@krsntn
Created November 12, 2021 02:19
Show Gist options
  • Select an option

  • Save krsntn/1edaccf28dcbbc51ef1051921c4cb94a to your computer and use it in GitHub Desktop.

Select an option

Save krsntn/1edaccf28dcbbc51ef1051921c4cb94a to your computer and use it in GitHub Desktop.
var total = 0;
var order = 0;
function calculate(next) {
var opts = { method: 'GET', headers: {} };
fetch(
'https://shopee.com.my/api/v4/coin/get_user_coin_transaction_list?type=out&limit=20&offset=' +
next,
opts
)
.then(function (response) {
return response.json();
})
.then(function (body) {
let next_offset = next + 20;
if (body.data.coin_transactions.length > 0) {
for (let item of body.data.coin_transactions) {
if (item.order_id === 0 && item.type === 10) {
total += Math.abs(item.coin_amount);
order++;
const { ctime, name } = item;
const dateTime = new Date(ctime * 1000);
console.log(
`${
dateTime.getFullYear() +
'/' +
(dateTime.getMonth() + 1) +
'/' +
dateTime.getDate()
}\n${order}: ${name}\n${item.info?.reason}\n${item.coin_amount}`
);
}
}
calculate(next_offset);
} else {
console.log('TOTAL: ' + total);
}
});
}
calculate(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment