AtCoderDifficultyDisplay

display a difficulty of AtCoder Problems.

2020-04-01 기준 버전입니다. 최신 버전을 확인하세요.

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