AtCoder Submission Notes

Add notes to AtCoder submissions

2025/03/03のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         AtCoder Submission Notes
// @namespace    https://greatest.deepsurf.us/users/your-username
// @version      1.4
// @description  Add notes to AtCoder submissions
// @author       zerozero-0-0
// @match        https://atcoder.jp/contests/*/submissions/me
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  function getNoteKey(submissionId) {
    return `atcoder_note_${submissionId}`;
  }

  const table = document.querySelector("table");
  if (!table) return;

  // ヘッダーに「Note」列を追加(重複防止)
  const headerRow = table.querySelector("thead tr");
  if (headerRow && !headerRow.querySelector(".note-header")) {
    const noteHeader = document.createElement("th");
    noteHeader.textContent = "Note";
    noteHeader.className = "note-header";
    headerRow.appendChild(noteHeader);
  }

  // 各行に独立したメモ欄追加
  document.querySelectorAll("tbody tr").forEach((row) => {
    const link = row.querySelector('a[href*="/submissions/"]');
    if (!link) return;

    const submissionId = link.href.split("/").pop();
    const noteKey = getNoteKey(submissionId);

    const td = document.createElement("td");
    td.style.minWidth = "200px";

    const textarea = document.createElement("textarea");
    textarea.style.width = "100%";
    textarea.style.height = "50px";
    textarea.dataset.submissionId = submissionId; // 念のため識別用
    textarea.value = localStorage.getItem(noteKey) || "";

    textarea.addEventListener("input", (event) => {
      const target = event.target;
      localStorage.setItem(noteKey, target.value);
    });

    td.appendChild(textarea);
    row.appendChild(td);
  });
})();