Advertisement
Guest User

Osu! beatmap play occurence

a guest
Feb 21st, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let uid = document.location.href.substring(25);
  2. let totalBMs = document.querySelector("div.user-profile-pages.ui-sortable > div:nth-child(4) > div > h3:nth-child(4) > span").textContent;
  3. async function getBMs(uid) {
  4.   let a = await fetch(`https://osu.ppy.sh/users/${uid}/beatmapsets/most_played?offset=1&limit=${totalBMs}`, {
  5.     "credentials": "include",
  6.     "headers": {
  7.       "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0",
  8.       "Accept": "*/*",
  9.       "Accept-Language": "en-US,en;q=0.5",
  10.       "X-CSRF-Token": "uy3Ba5IyVV5EITQHqiq3DNnlll9CEBRM2iVmmdKY",
  11.       "X-Requested-With": "XMLHttpRequest",
  12.       "Sec-GPC": "1"
  13.     },
  14.     "referrer": `https://osu.ppy.sh/users/${uid}`,
  15.     "method": "GET",
  16.     "mode": "cors"
  17.   });
  18.   let b = await a.json();
  19.   return(b);
  20. };
  21.  
  22. function foo(arr) {
  23.   var a = [],
  24.     b = [],
  25.     prev;
  26.  
  27.   arr.sort();
  28.   for (var i = 0; i < arr.length; i++) {
  29.     if (arr[i].count !== prev) {
  30.       a.push(arr[i].count);
  31.       b.push(1);
  32.     } else {
  33.       b[b.length - 1]++;
  34.     }
  35.     prev = arr[i].count;
  36.   }
  37.  
  38.   return [a, b];
  39. }
  40.  
  41. let info = await getBMs(uid);
  42. let result = foo(info);
  43. console.log('[' + result[0] + ']', '[' + result[1] + ']')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement