AtCoder Submission Notes

Add notes to AtCoder submissions

  1. // ==UserScript==
  2. // @name AtCoder Submission Notes
  3. // @namespace https://greatest.deepsurf.us/users/your-username
  4. // @version 2.1.0
  5. // @description Add notes to AtCoder submissions
  6. // @author zerozero-0-0
  7. // @match https://atcoder.jp/contests/*/submissions/me*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11. (function () {
  12. "use strict";
  13. const contestIdMatch = location.pathname.match(/contests\/([^/]+)/);
  14. const contestId = contestIdMatch ? contestIdMatch[1] : "unknown_contest";
  15. const table = document.querySelector("table");
  16. if (!table) return;
  17. const headerRow = table.querySelector("thead tr");
  18. if (headerRow && !headerRow.querySelector(".note-header")) {
  19. const noteHeader = document.createElement("th");
  20. noteHeader.textContent = "Note";
  21. noteHeader.className = "note-header";
  22. headerRow.appendChild(noteHeader);
  23. }
  24. const rows = Array.from(document.querySelectorAll("tbody tr"));
  25. rows.forEach((row) => {
  26. const dataIdElement = row.querySelector("[data-id]");
  27. const submissionId = dataIdElement ? dataIdElement.getAttribute("data-id") : "unknown_submission";
  28. const noteKey = `atcoder_note_${contestId}_row_${submissionId}`;
  29. const td = document.createElement("td");
  30. td.style.minWidth = "200px";
  31. const textarea = document.createElement("textarea");
  32. textarea.style.width = "100%";
  33. textarea.style.height = "50px";
  34. textarea.value = localStorage.getItem(noteKey) || "";
  35. textarea.addEventListener("input", (event) => {
  36. localStorage.setItem(noteKey, event.target.value);
  37. });
  38. td.appendChild(textarea);
  39. row.appendChild(td);
  40. });
  41.  
  42. })();