Atcoder Submission duration

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

当前为 2024-07-15 提交的版本,查看 最新版本

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

QingJ © 2025

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