Sploop IO KDR

Adds KDR to the profile stats

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
})();