AtCoder Jump to Submissions from Standings

順位表の得点をダブルクリックすると、該当するコンテスタントの実装を見ることができます。

当前为 2020-03-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AtCoder Jump to Submissions from Standings
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 順位表の得点をダブルクリックすると、該当するコンテスタントの実装を見ることができます。
  6. // @match https://atcoder.jp/contests/*/standings*
  7. // @require https://code.jquery.com/jquery-3.4.1.min.js
  8. // @author hiro_hiro
  9. // @license MIT
  10. // @supportURL https://github.com/KATO-Hiro/AtCoder-Jump-to-Submissions-from-Standings/issues
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. $(function() {
  15. 'use strict';
  16.  
  17. $(document).on('dblclick', '.standings-result', function() {
  18. const $standingsType = getStandingsType($('body'));
  19.  
  20. const $prefix = addPrefixIfNeeds($standingsType);
  21.  
  22. const $clickedColumnIndex = getClickedColumnIndex(this, $standingsType);
  23. const $taskUrls = $('body').find('thead a');
  24. const $taskId = getTaskId($taskUrls, $clickedColumnIndex);
  25.  
  26. const $username = getUserName(this);
  27.  
  28. const $displayLanguage = getDisplayLanguage($(location));
  29. const $suffix = addSuffixIfNeeds($displayLanguage);
  30.  
  31. // 順位表の範囲外なら、提出ページに遷移しない
  32. if ($clickedColumnIndex < $taskUrls.length) {
  33. // jumpToPersonalSubmissions($prefix, $taskId, $username);
  34. jumpToPersonalSubmissions($prefix, $taskId, $username, $suffix);
  35. }
  36. });
  37. })();
  38.  
  39. function getStandingsType(object) {
  40. let $standingsType = '';
  41. let isVirtual = $(object).find('script:contains("virtual")')[0];
  42. let isMultiply = $(object).find('script:contains("multiply_ranks")')[0];
  43.  
  44. // HACK: if分岐はメンテナンス的によくないかも
  45. // HACK: 他の言語のEnumに相当する構文がデフォルトで存在しない?
  46. if (isVirtual) {
  47. $standingsType = 'virtual';
  48. } else if (isMultiply) {
  49. $standingsType = 'multiply';
  50. } else {
  51. $standingsType = 'general';
  52. }
  53.  
  54. return $standingsType
  55. }
  56.  
  57. function addPrefixIfNeeds(standingsType) {
  58. let prefix = '';
  59.  
  60. if (standingsType != 'general') {
  61. prefix = '../';
  62. }
  63.  
  64. return prefix
  65. }
  66.  
  67. function getTaskId(taskUrls, clickedColumnIndex) {
  68. let $taskId = '';
  69.  
  70. taskUrls.each((index) => {
  71. if (index == clickedColumnIndex) {
  72. const $url = taskUrls[index].pathname;
  73. const $elements = $url.split('/');
  74. const $length = $elements.length;
  75.  
  76. $taskId = $elements[$length - 1]; // 0-indexed
  77. }
  78. });
  79.  
  80. return $taskId
  81. }
  82.  
  83. // HACK: 順位表の列数に応じた処理をしているため、AtCoderのUIが変更されると動かなくなる可能性がある
  84. // WHY : 順位表の得点の欄に、問題のIDが含まれていないため
  85. function getClickedColumnIndex(object, standingsType) {
  86. let $clickedColumnIndex = $(object)[0].cellIndex;
  87.  
  88. // コンテスト当日の順位表とバーチャル順位表の列の並びに違いがある
  89. // 当日の順位表の並びに合わせる
  90. if (standingsType == 'virtual') {
  91. $clickedColumnIndex -= 1
  92. }
  93.  
  94. // 順位とユーザ名の欄を扱わずに済むようにインデックスを補正
  95. // A問題がindex = 0となるようにしている
  96. $clickedColumnIndex -= 3
  97.  
  98. return $clickedColumnIndex
  99. }
  100.  
  101. function getUserName(object) {
  102. const $standings = $(object).siblings('td');
  103. const $username = $standings.find('.username span').text();
  104.  
  105. return $username
  106. }
  107.  
  108. function getDisplayLanguage(location) {
  109. let language = 'jp';
  110. const params = location.attr('search');
  111.  
  112. if (params.match(/lang=en/)) {
  113. language = 'en';
  114. }
  115.  
  116. return language
  117. }
  118.  
  119. function addSuffixIfNeeds($displayLanguage) {
  120. let suffix = '&lang=';
  121.  
  122. if ($displayLanguage == 'en') {
  123. suffix += 'en';
  124. } else {
  125. suffix = '';
  126. }
  127.  
  128. return suffix
  129. }
  130.  
  131. function jumpToPersonalSubmissions(prefix, taskId, username, suffix) {
  132. setTimeout(function() {
  133. location.href = `${prefix}submissions?f.Task=${taskId}&f.Language=&f.Status=AC&f.User=${username}${suffix}`;
  134. }, 250)
  135. }

QingJ © 2025

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