atcoder-lang

try to take over the world!

  1. // ==UserScript==
  2. // @name atcoder-lang
  3. // @namespace
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author uesugi
  7. // @match https://atcoder.jp/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. async function aaa() {
  13.  
  14. const res = await fetch("https://kenkoooo.com/atcoder/resources/lang.json", { cache: 'force-cache' });
  15. const list = await res.json();
  16.  
  17. Array.prototype.forEach.call(document.querySelectorAll('.username'), function (u) {
  18. if (!u.href.includes('/users/')) {
  19. return;
  20. }
  21. const user_id = u.text;
  22.  
  23. const angArray = fcfc(list, user_id);
  24. if (angArray.length === 0) {
  25. return;
  26. }
  27.  
  28.  
  29. const str_array = angArray.map((element) => {
  30. return element['language'] + ' : ' + element['count'];
  31. });
  32.  
  33. let lang = angArray[0]['language'];
  34.  
  35. const langSize = angArray.length;
  36.  
  37. let lang_str = '';
  38. if (langSize >= 3) {
  39. lang_str += '/' + angArray[2]['language'];
  40. }
  41. if (langSize >= 2) {
  42. lang += '<span style="font-size: 10px;">' + '/' + angArray[1]['language'] + lang_str + ' </span>';
  43. }
  44.  
  45. u.insertAdjacentHTML('beforeend', '/' + '<span data-toggle="tooltip" data-html="true" data-placement="right" style="font-size: 12px;" title="' + str_array.join('<br>') + '">' + lang + '</span>');
  46. $('[data-toggle="tooltip"]').tooltip();
  47. });
  48. }
  49.  
  50. function fcfc(list, user_id) {
  51. const trim_user_id = user_id.trim();
  52. const index = binary_search(list, trim_user_id);
  53. return sequence_search(trim_user_id, list, index);
  54.  
  55.  
  56. }
  57.  
  58. function binary_search(list, key) {
  59.  
  60. let left = -1;
  61. let right = list.length;
  62.  
  63.  
  64. while (right - left > 1) {
  65. let mid = Math.floor(left + (right - left) / 2);
  66.  
  67. if (isOK(mid, key, list)) {
  68. right = mid;
  69. } else {
  70. left = mid;
  71. }
  72. }
  73.  
  74.  
  75. return right;
  76. }
  77. function isOK(index, key, list) {
  78. if (list[index]['user_id'] >= key) {
  79. return true;
  80. }
  81. return false;
  82.  
  83.  
  84. }
  85. function sequence_search(user_id, list, index) {
  86.  
  87. let array = new Array();
  88. array = array.concat(search_one(user_id, list, index, 1));
  89. array = array.concat(search_one(user_id, list, index - 1, -1));
  90.  
  91. array.sort((a, b) => b['count'] - a['count']);
  92.  
  93. return array;
  94. }
  95. function search_one(user_id, list, index, add) {
  96. const array = new Array();
  97. while (1) {
  98. if (list[index]['user_id'] !== user_id) {
  99. break;
  100. }
  101. array.push(list[index]);
  102. index += add;
  103. }
  104.  
  105. return array;
  106. }
  107.  
  108. function bbb() {
  109. const target = document.querySelector('#standings-tbody');
  110.  
  111.  
  112. const observer = new MutationObserver(records => {
  113. aaa();
  114. });
  115.  
  116.  
  117. observer.observe(target, {
  118. subtree: true,
  119. childList: true
  120. });
  121. aaa();
  122. }
  123.  
  124.  
  125.  
  126. const MAX_RETRY_COUNT_FIND_DIFF_CONTAINER = 30;
  127. var retry_counter = 0;
  128.  
  129.  
  130. function getDiffContainerElements() {
  131. retry_counter++;
  132.  
  133. if (retry_counter > MAX_RETRY_COUNT_FIND_DIFF_CONTAINER) {
  134. clearInterval(set_interval_id);
  135. delete set_interval_id;
  136. }
  137. var diff_container_elements = document.getElementById('standings-tbody');
  138. if (diff_container_elements != null) {
  139. if (typeof (set_interval_id) != 'undefined') {
  140. clearInterval(set_interval_id);
  141. delete set_interval_id;
  142.  
  143. bbb();
  144. } else {
  145. return diff_container_elements;
  146. }
  147. }
  148. }
  149. var set_interval_id = setInterval(getDiffContainerElements, 1000);
  150.  
  151.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址