AtCoderFavSubmissionFilter

AtCoderの「すべての提出」の現在のページでお気に入りユーザー以外を非表示にする

Verze ze dne 23. 05. 2025. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name AtCoderFavSubmissionFilter
  3. // @namespace https://github.com/yayayaneko/AtCoderSubmissionFilters
  4. // @version 0.1.0
  5. // @description AtCoderの「すべての提出」の現在のページでお気に入りユーザー以外を非表示にする
  6. // @author yayayaneko
  7. // @license MIT
  8. // @match https://atcoder.jp/contests/*/submissions*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=atcoder.jp
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. "use strict";
  15. const fav = new Set(JSON.parse(localStorage.getItem("fav")) ?? []);
  16.  
  17. function addCheckbox(applyFilterCallback) {
  18. const target = document.querySelector(".panel-submission .panel-heading form > div:last-child");
  19. if (!target) return;
  20.  
  21. const containerDiv = document.createElement('div');
  22. const contentDiv = document.createElement("div");
  23. contentDiv.className = "checkbox";
  24. const label = document.createElement("label");
  25. const checkbox = document.createElement("input");
  26. checkbox.type = "checkbox";
  27. checkbox.id = "checkbox-fav-sub-only";
  28.  
  29. checkbox.checked = localStorage.getItem("fav-sub-only")==="true";
  30. checkbox.addEventListener("change", () => {
  31. localStorage.setItem("fav-sub-only", checkbox.checked);
  32. applyFilterCallback(checkbox.checked);
  33. });
  34.  
  35. label.appendChild(checkbox);
  36. label.appendChild(document.createTextNode(" お気に入りのみ表示"));
  37. contentDiv.appendChild(label);
  38. containerDiv.appendChild(contentDiv)
  39. target.after(containerDiv);
  40. }
  41.  
  42. function applyFilter(filterflg) {
  43. const rows = document.querySelectorAll("table tbody tr");
  44. rows.forEach(row => {
  45. const username = row.querySelector("td:nth-child(3)").innerText.trim();
  46. row.style.display = (filterflg && !fav.has(username)) ? "none" : "";
  47. });
  48. }
  49.  
  50. const observer = new MutationObserver(() => {
  51. const row = document.querySelector("tbody tr");
  52. if (row){
  53. observer.disconnect();
  54. addCheckbox(applyFilter);
  55. const lastState = localStorage.getItem("fav-sub-only")==="true";
  56. applyFilter(lastState);
  57. }
  58. });
  59.  
  60. observer.observe(document.body, {
  61. childList: true,
  62. subtree: true
  63. });
  64. })();