Codeforces Performance

You can check your performance for each contest!

当前为 2020-09-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            Codeforces Performance
// @name:ja         Codeforces Performance
// @namespace       https://github.com/Coki628/cf-perf
// @version         1.0.7
// @description     You can check your performance for each contest!
// @description:ja  Codeforcesのコンテストでのパフォーマンス推定値を確認します。
// @author          Coki628
// @license         MIT
// @include         https://codeforces.com/contests/with/*
// @grant           none
// ==/UserScript==

// ---------- your settings hare ----------

// colorize your rate (1 or 0)
const colorRate = 1;
// colorize your perf (1 or 0)
const colorPerf = 1;
// show your perf (1 or 0)
const showPerf = 1;

// ----------------------------------------

let getColorType = function(x) {
    if (x >= 3000) {
        return 'user-legendary';
    } else if (3000 > x && x >= 2400) {
        return 'user-red';
    } else if (2400 > x && x >= 2100) {
        return 'user-orange';
    } else if (2100 > x && x >= 1900) {
        return 'user-violet';
    } else if (1900 > x && x >= 1600) {
        return 'user-blue';
    } else if (1600 > x && x >= 1400) {
        return 'user-cyan';
    } else if (1400 > x && x >= 1200) {
        return 'user-green';
    } else {
        return 'user-gray';
    }
}

$(function() {
    'use strict';

    // 必要な要素を取得
    let $thead = $('table.user-contests-table>thead');
    let $tbody = $('table.user-contests-table>tbody');
    let th = $thead.find('th');
    let tr = $tbody.find('tr');

    // ヘッダ行に列を追加
    if (showPerf) {
        let $head = $(th[5]).clone();
        $head.text('Performance');
        $(th[5]).after($head);
    }

    // 各行
    for (let i=0; i<tr.length; i++) {
        // 変化量とレートを取得
        let td = $(tr[i]).find('td');
        let change = Number($(td[4]).text());
        let $rate = $(td[5]);
        let rate = Number($rate.text());

        // パフォーマンス列を表示
        if (showPerf) {
            // パフォーマンスを計算
            let prev = rate - change;
            let perf = prev + change * 4;
            // 列を追加
            let $perf = $rate.clone();
            $perf.text(perf);
            $rate.after($perf);
            // パフォーマンスの色付け
            if (colorPerf) {
                let colorType = getColorType(perf);
                $perf.addClass(colorType);
                $perf.css('font-weight', 'bold');
            }
        }
        // レートの色付け
        if (colorRate) {
            let colorType = getColorType(rate);
            $rate.addClass(colorType);
            $rate.css('font-weight', 'bold');
        }
    }

    // ソートが2重にかかってしまうので1回イベントをリセットする
    $('table.user-contests-table th').unbind();
    // テーブルのソートを再設定
    $("table.user-contests-table").tablesorter({
        headers: {
            1: { sorter: false },
            // 列が増えた分、ここを6→7に
            7: { sorter: false },
        }
    });
});