AtCoderPenaltyRateCheckEaser

提出フォームの上にペナルティ率を表示して、提出前に確認しやすくします

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         AtCoderPenaltyRateCheckEaser
// @namespace    http://tampermonkey.net/
// @version      0.2.2
// @description  提出フォームの上にペナルティ率を表示して、提出前に確認しやすくします
// @author       Masaoki Seta
// @match        https://atcoder.jp/contests/*/tasks/*
// @license      MIT
// ==/UserScript==

function getStandingsData(contestName) {
  const REQUEST_URL = `https://atcoder.jp/contests/${contestName}/standings/json`;
  return $.ajax({
    type: 'GET',
    url: REQUEST_URL,
    dataType: 'json',
  })
  .fail(() => console.error(`AtCoderPenaltyRateCheckEaser: Could not get data in function, getStandingsData. Request URL : ${REQUEST_URL}`));
}

$(() => {
  'use strict';

  if (!'contestScreenName' in window) {
    console.error('AtCoderPenaltyRateCheckEaser: Could not get contestScreenName.');
    return;
  }

  function gotPenalty(preblemData) {
    if (preblemData.Penalty > 0) return true;
    if (preblemData.Failure > 0 && preblemData.Status !== 1) return true;
    return false;
  }

  function gotCorrect(preblemData) {
    return preblemData.Status === 1;
  }

   const PROBLEM_NAME = location.href.split('/').pop();

   getStandingsData(contestScreenName).done((res) => {
      const standingsData = res.StandingsData;
      let totalCount = 0, penaltyCount = 0, acCount = 0;
      standingsData.forEach((userData) => {
        const problemData = userData.TaskResults[PROBLEM_NAME];
        if (problemData == null) return;
        totalCount++;
        if (gotPenalty(problemData)) penaltyCount++;
        if (gotCorrect(problemData)) acCount++;
      });
      const panaltyRate = penaltyCount * 100/totalCount;
      const panaltyRateStr = totalCount > 0 ? (panaltyRate).toFixed(2) + '%' : 'No Submit';
      const makeRateStyle = ((rate) => {
        let style = '';
        if (rate >= 33.3) style = 'background: red;';
        else if (rate >= 20.0) style = 'background: yellow;';
        return style;
      });
      const panaltyRateStyle = makeRateStyle(panaltyRate);

      const acRate = acCount * 100 / totalCount;
      // const acRateStr = totalCount > 0 ? (acRate).toFixed(2) + '%' : 'No Submit';
      // const acRateStyle = makeRateStyle(acCount);

      $('.form-horizontal.form-code-submit').prepend(`
<div>
<table id="acsa-table" class="table table-bordered table-hover th-center td-center td-middle">
  <thead>
    <th style="width: 34%">ノーペナ者数/提出者数</th>
    <th style="width: 33%">ペナルティ率</th>
    <th style="width: 33%">正解者数/提出者数</th>
  </thead>
  <tbody>
    <td>${ totalCount - penaltyCount }/${ totalCount }</td>
    <td style="${ panaltyRateStyle }">${ panaltyRateStr }</td>
    <td>${ acCount }/${ totalCount }</td>
  </tbody>
</table>
</div>
      `);
    });
});