AtCoder - You're top X%

Displays your approximate ranking percentile among all active AtCoder users on your profile page.

2024-10-05 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         AtCoder - You're top X%
// @namespace    https://gist.github.com/k1832/9438a1469bb2fa94d26702e1556aff97
// @version      1.0
// @description  Displays your approximate ranking percentile among all active AtCoder users on your profile page.
// @author       k1832
// @match        https://atcoder.jp/users/*
// @license      MIT License, Copyright (c) 2024 Keita Morisaki
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';

    const url = new URL(window.location.href);
    const contestType = url.searchParams.get('contestType');

    if (contestType === 'algo' || contestType === null) {
        /*
         * EN: Fetch the total number of active AtCoder users from a JSON file hosted on GitHub.
         * JA: GitHub でホストされている JSON ファイルから、AtCoder のアクティブユーザーの総数を取得します。
         */
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://k1832.github.io/atcoder-api/api/v1/total-active-users.json",
            onload: function (response) {
                const data = JSON.parse(response.responseText);
                const totalCount = data.val;

                let rankNode = document.evaluate(
                    '//th[text()="順位" or text()="Rank"]/following-sibling::td',
                    document,
                    null,
                    XPathResult.ANY_TYPE,
                    null
                ).iterateNext();

                if (!rankNode) {
                    console.error('Ranking element not found.');
                    return;
                }

                const rankText = rankNode.textContent;

                // "8956th" -> 8956
                const rank = parseInt(rankText.slice(0, -2), 10);
                const percentage = rank / totalCount * 100;
                rankNode.textContent += ` (top ${percentage.toFixed(2)}%)`;
            },
            onerror: function (error) {
                console.error('Error fetching user count:', error);
            }
        });
    }
})();