Jstris PC stats

Shows you PC stats on Jstris replays

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Jstris PC stats
// @namespace    Jstris PC stats
// @version      0.1.1
// @description  Shows you PC stats on Jstris replays
// @author       TSTman
// @match        https://jstris.jezevec10.com/replay/*
// @grant        none
// ==/UserScript==

(function setupStats() {
    'use strict';
    try {
        const statsToHide = ['Attack', 'Finesse', 'PPS', 'KPP'];
        const statTable =document.querySelector('#statTable');
        [...statTable.querySelectorAll(':scope tr td.ter')].filter(element => statsToHide.includes(element.textContent)).forEach(element => element.parentElement.style.display = 'none');
        const piecesElement = [...statTable.querySelectorAll(':scope tr td.sval')].filter(element => element.previousSibling.textContent === '#')[0];
        piecesElement.previousSibling.textContent = 'Piece';

        const linesRow = statRow('Line');
        const linesElement = linesRow.querySelector(':scope td.sval');
        const bagRow = statRow('Bag');
        const bagElement = bagRow.querySelector(':scope td.sval');
        const loopRow = statRow('Loop');
        const loopElement = loopRow.querySelector(':scope td.sval');

        function statRow(name) {
            const row = document.createElement('tr');
            const titleElement = document.createElement('td');
            const valueElement = document.createElement('td');
            titleElement.setAttribute('width', 120);
            titleElement.classList.add('ter');
            titleElement.textContent = name;
            valueElement.classList.add('sval');
            row.appendChild(titleElement);
            row.appendChild(valueElement);
            statTable.appendChild(row);
            return row;
        }

        setInterval(updateStats, 200);
        function updateStats() {
            const factor = 5;
            const pieceCount = parseInt(piecesElement.textContent);
            const lines = ((pieceCount / 2.5) % 14).toFixed(factor) + ' / 14';
            const bags = ((pieceCount / 7) % 5).toFixed(factor) + ' / 5';
            const loops = (pieceCount / 35).toFixed(factor);
            linesElement.textContent = lines;
            bagElement.textContent = bags;
            loopElement.textContent = loops;
        }
    } catch (e) {
        setTimeout(setupStats, 1000);
    }
})();