AtCoderDifficultyDisplay

display a difficulty of AtCoder Problems.

As of 02.03.2020. See ბოლო ვერსია.

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