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.

Από την 12/04/2023. Δείτε την τελευταία έκδοση.

  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.2
  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. // @license MIT
  9. // @match https://atcoder.jp/contests/*/tasks/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // ==/UserScript==
  13.  
  14. (async function () {
  15. const linkSettings = [
  16. {
  17. label: "Fastest",
  18. icon: "time",
  19. urlParams: "f.Status=AC&orderBy=time_consumption",
  20. },
  21. {
  22. label: "Shortest",
  23. icon: "flag",
  24. urlParams: "f.Status=AC&orderBy=source_length",
  25. },
  26. ];
  27.  
  28. const pathArray = window.location.pathname.split("/");
  29. const taskId = pathArray[pathArray.length - 1];
  30. const contestId = pathArray[2];
  31. const submissionsUrl = `https://atcoder.jp/contests/${contestId}/submissions`;
  32.  
  33. const cachedLinksHtml = GM_getValue(
  34. `atcoder-submission-shortcuts:${contestId}:${taskId}`
  35. );
  36. if (cachedLinksHtml) {
  37. addLinksToDom(cachedLinksHtml);
  38. } else {
  39. const response = await fetch(submissionsUrl, { method: "HEAD" });
  40. if (response.ok) {
  41. const linksHtml = linkSettings
  42. .map(({ label, icon, urlParams }) =>
  43. createButtonHtml(submissionsUrl, taskId, label, icon, urlParams)
  44. )
  45. .join("");
  46. GM_setValue(
  47. `atcoder-submission-shortcuts:${contestId}:${taskId}`,
  48. linksHtml
  49. );
  50. addLinksToDom(linksHtml);
  51. }
  52. }
  53.  
  54. function createButtonHtml(submissionsUrl, taskId, label, icon, urlParams) {
  55. const buttonUrl = `${submissionsUrl}?${urlParams}&f.Task=${taskId}`;
  56. return `<li><a href="${buttonUrl}"><span class="glyphicon glyphicon-${icon}" style="margin-right:4px;" aria-hidden="true"></span>${label}</a></li>`;
  57. }
  58.  
  59. function addLinksToDom(linksHtml) {
  60. const pullRightListItem = document.querySelector("li.pull-right");
  61. if (pullRightListItem) {
  62. pullRightListItem.insertAdjacentHTML("beforebegin", linksHtml);
  63. }
  64. }
  65. })();