AtCoder Dropdown Tasks

AtCoder のコンテストページにおいて、問題タブをホバーするとドロップダウンリストを表示するようにします。

目前为 2025-03-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name AtCoder Dropdown Tasks
  3. // @namespace https://atcoder.jp/
  4. // @version 2025-03-06
  5. // @description AtCoder のコンテストページにおいて、問題タブをホバーするとドロップダウンリストを表示するようにします。
  6. // @author magurofly
  7. // @match https://atcoder.jp/contests/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=atcoder.jp
  9. // @grant unsafeWindow
  10. // @license CC0-1.0 Universal
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16. const styleSheet = new CSSStyleSheet();
  17. styleSheet.insertRule(`
  18. .atcoder-dropdown-tasks:hover .dropdown-menu {
  19. display: block;
  20. }
  21. `);
  22. document.adoptedStyleSheets.push(styleSheet);
  23.  
  24. if (typeof unsafeWindow.contestScreenName !== "string") return;
  25. const contestScreenName = unsafeWindow.contestScreenName;
  26.  
  27. const tasksHTML = await (await fetch(`/contests/${contestScreenName}/tasks`)).text();
  28.  
  29. const tasksDropdown = unsafeWindow.document.querySelector("#contest-nav-tabs > ul > li:nth-child(2)");
  30. tasksDropdown.classList.add("atcoder-dropdown-tasks");
  31.  
  32. const tasksDropdownButton = tasksDropdown.querySelector("a");
  33. tasksDropdownButton.insertAdjacentHTML("beforeend", `<span class="caret"></span>`);
  34.  
  35. const tasksDropdownContents = document.createElement("ul");
  36. tasksDropdownContents.className = "dropdown-menu";
  37. tasksDropdown.appendChild(tasksDropdownContents);
  38.  
  39. const tasksDoc = new DOMParser().parseFromString(tasksHTML, "text/html");
  40. for (const row of tasksDoc.querySelectorAll("#main-container > div.row > div:nth-child(2) > div.panel.panel-default.table-responsive > table > tbody > tr")) {
  41. const taskNum = row.cells[0].textContent;
  42. const taskName = row.cells[1].textContent;
  43. const taskURL = row.cells[0].children[0].href;
  44. tasksDropdownContents.insertAdjacentHTML("beforeend", `<li><a href="${taskURL}">${taskNum} - ${taskName}</a></li>`);
  45. }
  46. })();