Sploop IO KDR

Adds KDR to the profile stats

スクリプトをインストールするには、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         Sploop IO KDR
// @namespace    lore
// @version      beta - v1
// @description  Adds KDR to the profile stats
// @author       lore
// @license      MIT
// @match        *://*sploop.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function calculateKDR() {
        const totalKillsElement = document.getElementById('total-kill');
        const totalDeathsElement = document.getElementById('total-death');
        const kdrElement = document.getElementById('kdrr');

        if (totalKillsElement && totalDeathsElement && kdrElement) {
            const totalKills = parseInt(totalKillsElement.textContent, 10);
            const totalDeaths = parseInt(totalDeathsElement.textContent, 10);

            if (!isNaN(totalKills) && !isNaN(totalDeaths)) {
                const kdr = totalDeaths === 0 ? totalKills : (totalKills / totalDeaths).toFixed(2);
                kdrElement.textContent = kdr;
            }
        }
    }

    function addKDRElement() {
        const bestKillElement = document.querySelector('div > div.text-shadowed-3.profile-score[id="best-kill"]').parentElement;

        if (bestKillElement) {
            const kdrElement = document.createElement('div');
            kdrElement.innerHTML = `
                <div class="text-shadowed-3 profile-score">KDR</div>
                <div class="text-shadowed-3 profile-score yellow-text" id="kdrr">0</div>
            `;

            bestKillElement.parentNode.insertBefore(kdrElement, bestKillElement.nextSibling);
            setInterval(calculateKDR, 500);
        }
    }

    function checkAndAddKDRElement() {
        const bestKillElement = document.querySelector('div > div.text-shadowed-3.profile-score[id="best-kill"]');
        if (bestKillElement) {
            addKDRElement();
            observer.disconnect();
        }
    }

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