AtCoder Submission User Colorizer

提出一覧のユーザ名を色付けします

As of 2020-03-11. See the latest version.

  1. // ==UserScript==
  2. // @name AtCoder Submission User Colorizer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 提出一覧のユーザ名を色付けします
  6. // @author morio_prog
  7. // @match https://atcoder.jp/contests/*/submissions*
  8. // @grant none
  9. // @license CC0
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  11. // @require https://unpkg.com/lscache/lscache.min.js
  12. // ==/UserScript==
  13.  
  14. function getcolor(rating) {
  15. if (rating >= 2800) return '#FF0000';
  16. if (rating >= 2400) return '#FF8000';
  17. if (rating >= 2000) return '#C0C000';
  18. if (rating >= 1600) return '#0000FF';
  19. if (rating >= 1200) return '#00C0C0';
  20. if (rating >= 800) return '#008000';
  21. if (rating >= 400) return '#804000';
  22. if (rating >= 0) return '#808080';
  23. return '#000000';
  24. }
  25.  
  26. function getcolorclass(rating) {
  27. if (rating >= 2800) return 'user-red';
  28. if (rating >= 2400) return 'user-orange';
  29. if (rating >= 2000) return 'user-yellow';
  30. if (rating >= 1600) return 'user-blue';
  31. if (rating >= 1200) return 'user-cyan';
  32. if (rating >= 800) return 'user-green';
  33. if (rating >= 400) return 'user-brown';
  34. if (rating >= 0) return 'user-gray';
  35. return 'user-unrated';
  36. }
  37.  
  38. function getachrate(rating) {
  39. var base = Math.floor(rating / 400) * 400;
  40. return ((rating - base) / 400) * 100;
  41. }
  42.  
  43. function colorize(u, rating) {
  44. /* */if (rating >= 4000) $(u).before('<img style="vertical-align: middle;" src="//img.atcoder.jp/assets/icon/crown4000.gif">&nbsp;');
  45. else if (rating >= 3600) $(u).before('<img style="vertical-align: middle;" src="//img.atcoder.jp/assets/icon/crown3600.gif">&nbsp;');
  46. else if (rating >= 3200) $(u).before('<img style="vertical-align: middle;" src="//img.atcoder.jp/assets/icon/crown3200.gif">&nbsp;');
  47. else {
  48. var color = getcolor(rating);
  49. var achrate = getachrate(rating);
  50. $(u).before(`
  51. <span style="
  52. display: inline-block;
  53. height: 12px;
  54. width: 12px;
  55. vertical-align: center;
  56. border-radius: 50%;
  57. border: solid 1px ${color};
  58. background: -webkit-linear-gradient(
  59. bottom,
  60. ${color} 0%,
  61. ${color} ${achrate}%,
  62. rgba(255, 255, 255, 0.0) ${achrate}%,
  63. rgba(255, 255, 255, 0.0) 100%);
  64. "></span>
  65. `);
  66. }
  67. $(u).addClass(getcolorclass(rating));
  68. }
  69.  
  70. $(function() {
  71. 'use strict';
  72.  
  73. lscache.flushExpired();
  74.  
  75. $('a[href*="/users"]').each(function(i, u) {
  76. // Skip "My Profile"
  77. if ($(u).find('span').length) return true;
  78.  
  79. var username = $(this).attr('href').slice(7);
  80. var lskey = "rating-" + username;
  81. var rating = lscache.get(lskey);
  82. if (rating === null) {
  83. $.ajax({
  84. url: "https://atcoder.jp" + $(this).attr('href') + "/history/json",
  85. type: 'GET',
  86. dataType: 'json'
  87. })
  88. .done(function(data) {
  89. var ratedcount = data.length;
  90. if (ratedcount == 0) {
  91. rating = 0;
  92. } else {
  93. rating = data[ratedcount - 1]["NewRating"];
  94. }
  95. // 12 hours
  96. lscache.set(lskey, rating, 12 * 60);
  97. })
  98. .then(function() {
  99. colorize(u, rating);
  100. });
  101. } else {
  102. colorize(u, rating);
  103. }
  104. });
  105. });