AtCoderColouringDifference

Color difference values of AtCoder's gradebook

Από την 29/08/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         AtCoderColouringDifference
// @namespace    https://chocobo777.github.io
// @version      0.0.1
// @description  Color difference values of AtCoder's gradebook
// @author       chocobo
// @include      https://beta.atcoder.jp/users/*/history
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==


$(function() {
  'use strict';

  // -------------->8---------------------------->8--------------

  // 色づけモードには以下の数値を指定します
  // -        0 : なし
  // -        1 : 文字を色づけ
  // -        2 : 背景を色づけ
  // - それ以外 : デフォルト設定

  // パフォーマンス値の色づけモード
  const perfColorizeMode = 2;

  // レート値の色づけモード
  const rateColorizeMode = 2;

  // --------------8<----------------------------8<--------------

  // 読み込み元と整合性を取る
  // https://wiki.greasespot.net/Third-Party_Libraries
  this.$ = this.jQuery = jQuery.noConflict(true);

  // レート値をカラーコードに変換 (背景色で使用)
  function convertRateToColorCode(rate){
      if(rate >= 2800) return '#FFB2B2';
      if(rate >= 2400) return '#FFD9B2';
      if(rate >= 2000) return '#ECECB2';
      if(rate >= 1600) return '#B2B2FF';
      if(rate >= 1200) return '#B2ECEC';
      if(rate >=  800) return '#B2D9B2';
      if(rate >=  400) return '#D9C5B2';
                       return '#D9D9D9';
  }

  // レート値を色クラス名に変換 (文字色で使用)
  function convertRateToColorClass(rate){
      if(rate >= 2800) return 'user-red';
      if(rate >= 2400) return 'user-orange';
      if(rate >= 2000) return 'user-yellow';
      if(rate >= 1600) return 'user-blue';
      if(rate >= 1200) return 'user-cyan';
      if(rate >=  800) return 'user-green';
      if(rate >=  400) return 'user-brown';
                       return 'user-gray';
  }

  // セルをmodeで色づけ
  function colorizeCell(cell, mode){
      const value = cell.text();
      console.log(cell);
      if(isNaN(value)) return;

      if (mode == 0) { // なし
          cell.text(value);
      }
      else if (mode == 1) { // 文字を色づけ
          cell.text('');
          cell.append('<span class="' + convertRateToColorClass(value) + '">' + value + '</span>');
      }
      else if (mode == 2) { // 背景を色づけ
          cell.text(value);
          cell.attr('style', 'background-color:' + convertRateToColorCode(value) + ';>');
      }
  }

  $('#history').find('tbody').find('tr').each(function(i, contestInfo) {
      const tds = $(contestInfo).find('td');
      colorizeCell($(tds[3]), perfColorizeMode);
      colorizeCell($(tds[4]), rateColorizeMode);
  });
});