Atcoder AC Submission Duration

AtCoderの順位表で、その問題をACするのにかかった時間を表示する

当前为 2024-10-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Atcoder AC Submission Duration
  3. // @namespace https://oginoshikibu.github.io/
  4. // @version 0.4
  5. // @description AtCoderの順位表で、その問題をACするのにかかった時間を表示する
  6. // @match https://atcoder.jp/contests/*/standings
  7. // @match https://atcoder.jp/contests/*/standings/virtual
  8. // @author oginoshikibu
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. const observer = new MutationObserver((mutations, obs) => {
  13. const $standingsTbody = $('#standings-tbody');
  14. if ($standingsTbody.length) {
  15. $standingsTbody.find('tr').each(function () {
  16. let times = [];
  17. $(this).find('.standings-result').slice(1).each(function () {
  18. const $td = $(this);
  19. const $timeP = $td.find('p').last(); // 時間を含む<p>タグを取得
  20. const timeText = $timeP.text(); // <p>タグのテキスト(時間)を取得
  21.  
  22. // 正規表現で時間の形式にマッチするかチェック
  23. if (/^\d+:\d{2}$/.test(timeText)) {
  24. times.push({ time: timeText, element: $timeP });
  25. }
  26. });
  27.  
  28. if (times.length === 0) {
  29. return;
  30. }
  31.  
  32. times.push({ time: '0:00', element: null });
  33.  
  34. // 時間を昇順でソート
  35. times.sort((a, b) => {
  36. const [aMin, aSec] = a.time.split(':').map(Number);
  37. const [bMin, bSec] = b.time.split(':').map(Number);
  38. return aMin * 60 + aSec - (bMin * 60 + bSec);
  39. });
  40.  
  41. // 時間差を計算して表示
  42. for (let i = 1; i < times.length; i++) {
  43. const diff = calculateTimeDifference(times[i - 1].time, times[i].time);
  44. times[i].element.text(`${times[i].time} (${diff})`);
  45. }
  46.  
  47. });
  48.  
  49. // 目的の要素が見つかったので、Observerを停止する
  50. obs.disconnect();
  51. }
  52.  
  53. });
  54.  
  55. // Observerの設定
  56. observer.observe(document, {
  57. childList: true,
  58. subtree: true
  59. });
  60.  
  61.  
  62. // 時間の差を計算する関数
  63. function calculateTimeDifference(startTime, endTime) {
  64. const [startMinutes, startSeconds] = startTime.split(':').map(Number);
  65. const [endMinutes, endSeconds] = endTime.split(':').map(Number);
  66. const startTotalSeconds = startMinutes * 60 + startSeconds;
  67. const endTotalSeconds = endMinutes * 60 + endSeconds;
  68. const diff = endTotalSeconds - startTotalSeconds;
  69.  
  70. const minutes = Math.floor(diff / 60);
  71. const seconds = diff % 60;
  72.  
  73. return `${minutes}:${seconds.toString().padStart(2, '0')}`;
  74. }

QingJ © 2025

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