AtCoder Submission Status

AtCoderで提出した解答がいくつのテストケースでACか, WAか...が一目でわかるように表示する

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AtCoder Submission Status
// @name:en      AtCoder Submission Status
// @namespace    https://github.com/9sako6/atcoder-userscripts
// @version      1.2
// @description  AtCoderで提出した解答がいくつのテストケースでACか, WAか...が一目でわかるように表示する
// @description:en This script shows submission's statuses clearly!
// @author       9sako6
// @match        https://atcoder.jp/contests/*/submissions/*
// @exclude      https://atcoder.jp/contests/*/submissions/me
// @license     MIT
// @supportURL   https://github.com/9sako6/atcoder-userscripts/issues
// ==/UserScript==

function main() {
  /**
  * count each status
  */
  const statusPanel = document.getElementsByClassName('panel-default')[2];
  const testCaseElems = statusPanel.querySelector('tbody').querySelectorAll('tr');
  const statusCounter = {};

  testCaseElems.forEach((elem) => {
    const statusCodeColumnNum = 1;
    const statusCode = elem.querySelectorAll('td')[statusCodeColumnNum].querySelector('span').textContent;

    statusCounter[statusCode] ? statusCounter[statusCode]++ : statusCounter[statusCode] = 1;
  });

  const statusCodes = Object.keys(statusCounter).sort();

  /**
   * make result table
   */
  // NOTE: Don't use `<table></table>` to avoid conflict 'AtCoder TestCase Extension'.
  const testCasesCount = testCaseElems.length;
  const rowWidthPercent = 100 / statusCodes.length;

  const resultTable = `
    <div class="table table-bordered table-striped th-center">
      <div style="width: 100%; display: flex;">
      ${statusCodes.map((status, index) => `<div style="width: ${rowWidthPercent}%; text-align: center; border: 0.1px solid #ddd; border-top: 0; border-bottom: 0; border-right: 0; ${index == 0 ? "border-left: 0;" : ""}">
            <div style="line-height: 2em; border: 0.1px solid #ddd; border-top: 0; border-right: 0; border-left: 0; border-bottom: 1;">
              <span class="label label-${status === 'AC' ? 'success' : 'warning'}" aria-hidden="true" data-toggle="tooltip" data-placement="top" style="text-align: center; line-height: 2em;">${status}</span>
            </div>
          <div style="line-height: 1.8em;">${statusCounter[status]}/${testCasesCount}</div>
        </div>`).join('')}
      </div>
    </div>`;

  // NOTE: Create a wrapper element of table.
  const wrapElem = document.createElement('div');
  wrapElem.id = 'added-result-panel';
  wrapElem.classList.add('panel', 'panel-default');
  wrapElem.appendChild(document.createTextNode(''));
  wrapElem.insertAdjacentHTML("beforeend", resultTable);

  statusPanel.parentNode.insertBefore(wrapElem, statusPanel);
}

(function () {
  try {
    main();
  } catch (_error) {
    // noop
  }
})();