BanScore

Подсчет блокировок и количества баллов

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         BanScore
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Подсчет блокировок и количества баллов
// @author       vuchaev2015
// @match        https://zelenka.guru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @grant        none
// ==/UserScript==

function debounce(func, wait) {
    let timeout;
    return function (...args) {
        const context = this;
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(context, args), wait);
    };
}

function calculateTotalWarningPoints() {
    let rows = document.querySelectorAll('.dataTable tbody .dataRow'), totalWarningPoints = 0;

    rows.forEach(row => {
        let warningPoints = parseInt(row.querySelector('.warningPoints')?.textContent || 0, 10);
        if (!isNaN(warningPoints)) totalWarningPoints += warningPoints;
    });

    console.log(`Общее количество warningPoints: ${totalWarningPoints}`);
    return totalWarningPoints;
}

function calculateTotalBlocks() {
    let logFields = document.querySelectorAll('.dataTable.userChangeLogs td.logField'), totalBlocks = 0;

    logFields.forEach(logField => {
        if (logField.textContent.trim() === 'Заблокирован(а)' && logField.parentNode.lastElementChild.textContent.trim() === 'Да') {
            totalBlocks++;
        }
    });

    console.log(`Общее количество блокировок: ${totalBlocks}`);
    return totalBlocks;
}

function observerWarningPointsCallback(mutations, observer) {
    mutations.forEach(mutation => {
        if (mutation.type === 'childList') {
            const rows = document.querySelectorAll('.dataTable tbody .dataRow');
            if (rows.length > 0) {
                const warningList = document.querySelector('.warningList');
                if (warningList && warningList.children.length > 0) {
                    let totalWarningPoints = calculateTotalWarningPoints();
                    let firstRow = rows[0];
                    let expiryHeader = firstRow.querySelector('.warningExpiry');
                    if (expiryHeader && !firstRow.querySelector('.warningTotal')) {
                        let totalHeader = document.createElement('th');
                        totalHeader.className = 'warningTotal';
                        totalHeader.setAttribute('width', '30%');
                        totalHeader.textContent = `Общее количество баллов (${totalWarningPoints})`;
                        expiryHeader.parentNode.insertBefore(totalHeader, expiryHeader.nextSibling);
                    }
                    observer.disconnect();
                }
            }
        }
    });
}

function observerBlocksCallback(mutations, observer) {
    mutations.forEach(mutation => {
        if (mutation.type === 'childList') {
            if (document.querySelector('.dataTable.userChangeLogs') && document.querySelectorAll('.dataTable.userChangeLogs td.logField').length > 0) {
                let totalBlocks = calculateTotalBlocks();
                let banLogsSection = document.querySelector('.banLogs.section');
                let dataRow = banLogsSection?.querySelector('.dataRow');
                let totalBanHeader = dataRow?.querySelector('.totalBans');
                let banHeader = dataRow?.querySelector('#change-logs > div > div > table > tbody > tr:nth-child(1) > th:nth-child(3)');
                if (!totalBanHeader && banHeader && totalBlocks) {
                    totalBanHeader = document.createElement('th');
                    totalBanHeader.className = 'totalBans';
                    totalBanHeader.setAttribute('width', '30%');
                    totalBanHeader.textContent = `Общее количество банов (${totalBlocks})`;

                    Array.from(document.querySelectorAll('tr.dataRow.secondaryContent>td')).forEach((cell) => {
                        cell.setAttribute('colspan', '4');
                    });

                    banHeader.parentNode.insertBefore(totalBanHeader, banHeader.nextSibling);
                } else if (totalBlocks) {
                     totalBanHeader.textContent = `Общее количество банов (${totalBlocks})`;
                }
                observer.disconnect();
            }
        }
    });
}

let config = { childList: true, subtree: true };
let observerWarningPoints = new MutationObserver(debounce(observerWarningPointsCallback, 10));
let observerBlocks = new MutationObserver(debounce(observerBlocksCallback, 10));


observerWarningPoints.observe(document.body, config);
observerBlocks.observe(document.body, config);