Nitro Type Leaderboards (Startrack Embed)

Adds a Leaderboards tab and loads ntstartrack.org/leaderboards inside Nitro Type’s layout

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Nitro Type Leaderboards (Startrack Embed)
// @namespace    https://ntstartrack.org
// @version      1.0
// @description  Adds a Leaderboards tab and loads ntstartrack.org/leaderboards inside Nitro Type’s layout
// @match        https://www.nitrotype.com/*
// @grant        none
// @author       Daymare
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const TAB_CLASS = 'nt-custom-leaderboards';

    function insertTab() {
        if (document.querySelector('.' + TAB_CLASS)) return;
        const nav = document.querySelector('.nav-list');
        if (!nav) return;

        const ach = Array.from(nav.children).find(li =>
            li.textContent.trim().includes('Achievements')
        );
        const li = document.createElement('li');
        li.className = `nav-list-item ${TAB_CLASS}`;
        li.innerHTML = `<a href="/leaderboards" class="nav-link"><span class="has-notify">Leaderboards</span></a>`;

        if (ach) ach.before(li);
        else nav.appendChild(li);
    }

    function setActiveTab() {
        document.querySelectorAll('.nav-list-item').forEach(li => li.classList.remove('is-current'));
        const tab = document.querySelector('.' + TAB_CLASS);
        if (tab) tab.classList.add('is-current');
    }

    function replace404() {
        const main = document.querySelector('main.structure-content');
        if (!main) return;
        if (main.querySelector('iframe[src*="ntstartrack.org"]')) return;

        main.innerHTML = `
            <section class="card card--b card--shadow card--o card--grit card--f mtxs mbm">
                <div class="well--p well--l_p pll" style="padding:0;">
                    <div style="display:flex;flex-direction:column;align-items:center;width:100%;">
                        <h1 class="tc-i mbs tbs" style="margin:20px 0 10px;">Leaderboards</h1>
                        <div style="width:100%;height:80vh;border-radius:8px;overflow:hidden;">
                            <iframe
                                src="https://ntstartrack.org/leaderboards"
                                style="width:100%;height:100%;border:none;"
                                loading="lazy">
                            </iframe>
                        </div>
                    </div>
                </div>
            </section>
        `;
        document.title = 'Leaderboards | Nitro Type';
        setActiveTab();
    }

    function handlePage() {
        insertTab();
        if (location.pathname === '/leaderboards') {
            const observer = new MutationObserver(() => {
                const err = document.querySelector('.error');
                if (err) {
                    replace404();
                    observer.disconnect();
                }
            });
            observer.observe(document.body, { childList: true, subtree: true });
        }
    }

    const obs = new MutationObserver(handlePage);
    obs.observe(document.body, { childList: true, subtree: true });
    handlePage();
})();