AtCoderDifficultyDisplay

display a difficulty of AtCoder Problems.

01.04.2020 itibariyledir. En son verisyonu görün.

  1. // ==UserScript==
  2. // @name AtCoderDifficultyDisplay
  3. // @namespace https://github.com/hotarunx
  4. // @version 0.1
  5. // @description display a difficulty of AtCoder Problems.
  6. // @description:ja AtCoder ProblemsのDifficultyを表示します。
  7. // @author hotarunx
  8. // @match https://atcoder.jp/contests/*/tasks/*
  9. // @grant none
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  11. // @connect https://kenkoooo.com/atcoder/resources/*
  12. // @license MIT
  13. //
  14. // Copyright(c) 2020 hotarunx
  15. // This software is released under the MIT License, see LICENSE or https://github.com/hotarunx/AtCoderMyExtensions/blob/master/LICENSE.
  16. //
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. // URL of Estimated difficulties of the problems
  21. const url = "https://kenkoooo.com/atcoder/resources/problem-models.json";
  22.  
  23. // get id
  24. const path = location.pathname.split("/");
  25. const id = path[path.length - 1];
  26.  
  27. // get Element of Problem Status
  28. let element_status
  29. const main_container = document.getElementById('main-container');
  30. const elements_p = main_container.getElementsByTagName("p");
  31. for (let i = 0; i < elements_p.length; i++) {
  32. const element = elements_p[i];
  33. if (element.textContent.match("メモリ制限:") || element.textContent.match("Memory Limit:")) {
  34. element_status = element;
  35. break
  36. }
  37. }
  38.  
  39. // fetch Information API
  40. this.fetch(url)
  41. .then(function (data) {
  42. return data.json();
  43. })
  44. .then(function (json) {
  45. // search problem
  46. const problem = json[id];
  47.  
  48. // if problem exist in json
  49. if (problem != null) {
  50. const difficulty = problem.difficulty;
  51.  
  52. // if difficulty is exist
  53. if (difficulty != null) {
  54. element_status.textContent += " / ";
  55.  
  56. // add difficulty value
  57. let add_text = "Difficulty: ";
  58. if (problem.is_experimental) add_text += "🧪";
  59. add_text += difficulty.toFixed();
  60.  
  61. // colorize text
  62. let color = '#FFFFFF'; // white
  63. if (difficulty < 400) color = '#808080'; // gray
  64. else if (difficulty < 800) color = '#804000'; // brown
  65. else if (difficulty < 1200) color = '#008000'; // green
  66. else if (difficulty < 1600) color = '#00C0C0'; // cyan
  67. else if (difficulty < 2000) color = '#0000FF'; // blue
  68. else if (difficulty < 2400) color = '#C0C000'; // yellow
  69. else if (difficulty < 2800) color = '#FF8000'; // orange
  70. else if (difficulty < 3200) color = '#FF0000'; // red
  71. else if (difficulty < 3600) color = '#E4E4E4'; // silver
  72. else /* */ color = '#FFD325'; // gold
  73.  
  74. const add_span = "<span style='color: " + color + ";'>" + add_text + "</span>";
  75.  
  76. element_status.innerHTML += add_span;
  77. }
  78. }
  79. })
  80. })();