CodeCombat Match Highlighter

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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