AtCoder Submission User Colorizer

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

Od 16.03.2020.. Pogledajte najnovija verzija.

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