Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function nx_spent_by_item() {
- const categories = {
- // If item contains {key}, then group it into {value}
- "Black Friday Lucky Box": "MapleStory - Black Friday Lucky Box",
- "Cube": "MapleStory - Cube",
- "Drop": "MapleStory - 2x Drop Coupon",
- "EXP": "MapleStory - 2x EXP Coupon",
- "Familiar": "MapleStory - Familiar-related Item",
- "Gachapon": "MapleStory - Gachapon",
- "Luna Crystal": "MapleStory - Wonderberry",
- "Maple Point": "MapleStory - Maple Point Coupons",
- "Marvel": "MapleStory - Marvel Machine",
- "Miracle": "MapleStory - Cube",
- "Philosopher": "MapleStory - Philosopher's Book",
- "Return Scroll": "MapleStory - Return Scroll",
- "Surprise Style Box": "MapleStory - Surprise Style Box",
- "Transparent": "MapleStory - Transparent Equip",
- "Wonderberry": "MapleStory - Wonderberry",
- }
- const count = 50
- const type = "out"
- const res = await fetch(`https://www.nexon.com/wallet-api/history?index=1&count=${count}&type=${type}`)
- const data = await res.json()
- let transactions = data.History.Transactions.map(t => [t.ItemName, t.Amount])
- const indices = [...Array(Math.ceil(data.History.Total/count) + 1).keys()].slice(2)
- await Promise.all(
- indices.map(async (index) => {
- const res = await fetch(`https://www.nexon.com/wallet-api/history?index=${index}&count=${count}&type=${type}`)
- const data = await res.json()
- const amounts = data.History.Transactions.map(t => [t.ItemName, t.Amount])
- transactions.push(...amounts)
- })
- )
- let sorted = Array.from(transactions.reduce((map, [item, amount]) => {
- for (const [key, value] of Object.entries(categories)) {
- if (item.includes(key)) {
- item = value
- break
- }
- }
- if (map.has(item)) {
- map.set(item, map.get(item) + amount)
- } else {
- map.set(item, amount)
- }
- return map
- }, new Map()))
- sorted.sort((a, b) => b[1] - a[1])
- let total = sorted.map(([_, amount]) => amount).reduce((p, c) => p + c, 0)
- console.log(`Total: ${total.toLocaleString()} NX`)
- sorted.forEach(([item, amount]) => {
- console.log(`${item}: ${amount.toLocaleString()} NX (${parseFloat(amount / total * 100).toFixed(2)} %)`)
- })
- }
- nx_spent_by_item()
Advertisement
Add Comment
Please, Sign In to add comment