CodeCombat Match Highlighter

扣哒世界竞技场对局记录优化显示

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         CodeCombat Match Highlighter
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  扣哒世界竞技场对局记录优化显示
// @author       younglet
// @license      MIT
// @match        https://koudashijie.com/play/ladder/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=koudashijie.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    function hack() {
        const userName = document.querySelector('h5').textContent;
        const table = document.querySelector('.my-matches-table');
        const trElements = table.querySelectorAll('tr[title]');
        const ladderTable = document.querySelector('.ladder-table tbody');

        let userRank = null
        for (let i = 0; i < ladderTable.children.length; i++) {
            const row = ladderTable.children[i];
            if (row.children[2].textContent.trim() === userName) {
                userRank = row.children[1].textContent.trim();
                break;
            }
        }
        trElements.forEach((tr) => {
            const tdElements = tr.children;
            const playerName = tdElements[2].textContent;

            let playerRank = null;
            for (let i = 0; i < ladderTable.children.length; i++) {
                const row = ladderTable.children[i];
                if (row.children[2].textContent.trim() === playerName) {
                    playerRank = row.children[1].textContent.trim();


                    break;
                }
            }
            tdElements[1].style = ''
            tdElements[1].classList = []

            let prefix = null
            if (playerRank) {
                prefix = '[' + playerRank + ']'
            }
            tdElements[1].textContent = prefix

            if (playerRank) {
                let distance = userRank - playerRank
                if (tdElements[0].textContent.trim() == '胜利' && distance > 0) {
                    tr.style.backgroundColor = 'lightgreen'
                }
                if (tdElements[0].textContent.trim() == '失败' && distance < 0) {
                    tr.style.backgroundColor = 'lightpink'
                }
            }
        });



    }

    setInterval(hack, 100)
})();