CodeCombat Match Highlighter

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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