Guest User

Untitled

a guest
Dec 1st, 2021
3,121
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function nx_spent_by_item() {
  2.     const categories = {
  3.         // If item contains {key}, then group it into {value}
  4.         "Black Friday Lucky Box":   "MapleStory - Black Friday Lucky Box",
  5.         "Cube":                     "MapleStory - Cube",
  6.         "Drop":                     "MapleStory - 2x Drop Coupon",
  7.         "EXP":                      "MapleStory - 2x EXP Coupon",
  8.         "Familiar":                 "MapleStory - Familiar-related Item",
  9.         "Gachapon":                 "MapleStory - Gachapon",
  10.         "Luna Crystal":             "MapleStory - Wonderberry",
  11.         "Maple Point":              "MapleStory - Maple Point Coupons",
  12.         "Marvel":                   "MapleStory - Marvel Machine",
  13.         "Miracle":                  "MapleStory - Cube",
  14.         "Philosopher":              "MapleStory - Philosopher's Book",
  15.         "Return Scroll":            "MapleStory - Return Scroll",
  16.         "Surprise Style Box":       "MapleStory - Surprise Style Box",
  17.         "Transparent":              "MapleStory - Transparent Equip",
  18.         "Wonderberry":              "MapleStory - Wonderberry",
  19.     }
  20.     const count = 50
  21.     const type = "out"
  22.     const res = await fetch(`https://www.nexon.com/wallet-api/history?index=1&count=${count}&type=${type}`)
  23.     const data = await res.json()
  24.     let transactions = data.History.Transactions.map(t => [t.ItemName, t.Amount])
  25.     const indices = [...Array(Math.ceil(data.History.Total/count) + 1).keys()].slice(2)
  26.     await Promise.all(
  27.         indices.map(async (index) => {
  28.             const res = await fetch(`https://www.nexon.com/wallet-api/history?index=${index}&count=${count}&type=${type}`)
  29.             const data = await res.json()
  30.             const amounts = data.History.Transactions.map(t => [t.ItemName, t.Amount])
  31.             transactions.push(...amounts)
  32.         })
  33.     )
  34.     let sorted = Array.from(transactions.reduce((map, [item, amount]) => {
  35.         for (const [key, value] of Object.entries(categories)) {
  36.             if (item.includes(key)) {
  37.                 item = value
  38.                 break
  39.             }
  40.         }
  41.         if (map.has(item)) {
  42.             map.set(item, map.get(item) + amount)
  43.         } else {
  44.             map.set(item, amount)
  45.         }
  46.         return map
  47.     }, new Map()))
  48.     sorted.sort((a, b) => b[1] - a[1])
  49.     let total = sorted.map(([_, amount]) => amount).reduce((p, c) => p + c, 0)
  50.     console.log(`Total: ${total.toLocaleString()} NX`)
  51.     sorted.forEach(([item, amount]) => {
  52.         console.log(`${item}: ${amount.toLocaleString()} NX (${parseFloat(amount / total * 100).toFixed(2)} %)`)
  53.     })
  54. }
  55. nx_spent_by_item()
Advertisement
Add Comment
Please, Sign In to add comment