AtCoder Add Submissions Shortcuts

Add links to the AtCoder task page that open a list of submissions for the current task with custom filters applied.

Verze ze dne 12. 04. 2023. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name AtCoder Add Submissions Shortcuts
  3. // @name:ja AtCoder Add Submissions Shortcuts
  4. // @namespace https://github.com/xe-o
  5. // @version 0.3
  6. // @description Add links to the AtCoder task page that open a list of submissions for the current task with custom filters applied.
  7. // @description:ja AtCoderの各問題ページのタブメニューに対して、任意のフィルター・並び順を適用した状態でその問題の提出一覧を開くリンクを追加します。
  8. // @author XERO
  9. // @license MIT
  10. // @match https://atcoder.jp/contests/*/tasks/*
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // ==/UserScript==
  14.  
  15. (async function () {
  16. const linkSettings = [
  17. {
  18. label: "Fastest",
  19. icon: "time",
  20. urlParams: "f.Status=AC&orderBy=time_consumption",
  21. },
  22. {
  23. label: "Shortest",
  24. icon: "flag",
  25. urlParams: "f.Status=AC&orderBy=source_length",
  26. },
  27. ];
  28.  
  29. const pathArray = window.location.pathname.split("/");
  30. const taskId = pathArray[pathArray.length - 1];
  31. const contestId = pathArray[2];
  32. const submissionsUrl = `https://atcoder.jp/contests/${contestId}/submissions`;
  33.  
  34. const cachedLinksHtml = GM_getValue(
  35. `atcoder-submission-shortcuts:${contestId}:${taskId}`
  36. );
  37. if (cachedLinksHtml) {
  38. addLinksToDom(cachedLinksHtml);
  39. } else {
  40. const response = await fetch(submissionsUrl, { method: "HEAD" });
  41. if (response.ok) {
  42. const linksHtml = linkSettings
  43. .map(({ label, icon, urlParams }) =>
  44. createButtonHtml(submissionsUrl, taskId, label, icon, urlParams)
  45. )
  46. .join("");
  47. GM_setValue(
  48. `atcoder-submission-shortcuts:${contestId}:${taskId}`,
  49. linksHtml
  50. );
  51. addLinksToDom(linksHtml);
  52. }
  53. }
  54.  
  55. function createButtonHtml(submissionsUrl, taskId, label, icon, urlParams) {
  56. const buttonUrl = `${submissionsUrl}?${urlParams}&f.Task=${taskId}`;
  57. return `<li><a href="${buttonUrl}"><span class="glyphicon glyphicon-${icon}" style="margin-right:4px;" aria-hidden="true"></span>${label}</a></li>`;
  58. }
  59.  
  60. function addLinksToDom(linksHtml) {
  61. const pullRightListItem = document.querySelector("li.pull-right");
  62. if (pullRightListItem) {
  63. pullRightListItem.insertAdjacentHTML("beforebegin", linksHtml);
  64. }
  65. }
  66. })();