shdewz / osu! BWS Calculator

// ==UserScript==
// @name osu! BWS Calculator
// @description Calculate BWS rank of users with the formula rank^(0.9937^(badges^2))
// @version 1.3
// @author shdewz
// @copyright 2022, shdewz (https://openuserjs.org/users/shdewz)
// @license MIT
// @icon https://shdewz.s-ul.eu/IeogjLJI
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @match *://osu.ppy.sh/users/*
// ==/UserScript==

/* jshint esversion: 6 */
/* globals jQuery, $, waitForKeyElements */

var ignored_descriptions = [
    'contrib',
    'nomination',
    'assessment',
    'moderation',
    'spotlight',
    'mapper',
    'mapping',
    'aspire',
    'monthly',
    'exemplary',
    'outstanding',
    'longstanding',
    'idol',
    'pending',
    'pickem',
    'gmt',
    'global moderators'
];

waitForKeyElements('.value-display.value-display--large', changeTitle);

function changeTitle() {
    let user = JSON.parse($('.js-react--profile-page.osu-layout.osu-layout--full')[0].dataset.initialData).user;
    let rank = user.statistics.global_rank;
    let badgesArray = user.badges;
    let badges = badgesArray.filter(badge => !ignored_descriptions.some(e => badge.description.toLowerCase().includes(e))).length;

    let bws_rank = badges > 0 ? Math.round(Math.pow(rank, Math.pow(0.9937, Math.pow(badges, 2)))) : parseInt(rank);
    let s = badges == 1 ? '' : 's';
    $('.profile-stats').append(`<dl class='profile-stats__entry'><dt class='profile-stats__key'>BWS Rank (` + badges + ` badge` + s + `)</dt><dd class='profile-stats__value'>#` + bws_rank.toLocaleString() + `</dd></dl>`);
}