AtCoder Companions Quick Jump

AtCoder CompanionsでCompanionsを探すためのボタンを提出画面に追加します。

  1. // ==UserScript==
  2. // @name AtCoder Companions Quick Jump
  3. // @namespace https://github.com/ryoryon66
  4. // @version 0.2
  5. // @description AtCoder CompanionsでCompanionsを探すためのボタンを提出画面に追加します。
  6. // @author ryoryon66
  7. // @match https://atcoder.jp/contests/*/submissions/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13.  
  14. function redirectToCompanions() {
  15. const urlPattern = /^https:\/\/atcoder\.jp\/contests\/([a-zA-Z0-9-]+)\/submissions\/(\d+)$/;
  16. const matches = window.location.href.match(urlPattern);
  17.  
  18. if (matches) {
  19. const contest = matches[1];
  20. const submissionId = matches[2];
  21. const url = `https://atcoder-companions.kakira.dev/?c=${contest}&sid=${submissionId}`;
  22. window.location.href = url;
  23. }
  24. }
  25.  
  26. function addRedirectButton() {
  27. const urlPattern = /^https:\/\/atcoder\.jp\/contests\/([a-zA-Z0-9-]+)\/submissions\/(\d+)$/;
  28. const matches = window.location.href.match(urlPattern);
  29.  
  30. if (matches) {
  31. const button = document.createElement("button");
  32. button.innerText = "See Companions";
  33. button.onclick = redirectToCompanions;
  34. button.style.cursor = "pointer";
  35. button.style.width = "70%";
  36. button.style.height = "40px";
  37. button.style.border = "none";
  38. button.style.borderRadius = "4px";
  39. button.style.backgroundColor = "#4CAF50";
  40. button.style.color = "white";
  41. button.style.fontWeight = "bold";
  42. button.style.fontSize = "16px";
  43. button.style.marginTop = "10px";
  44. button.style.marginBottom = "20px";
  45.  
  46. const sibling = document.querySelector("#contest-nav-tabs").nextElementSibling;
  47. if (sibling) {
  48. const container = document.createElement("div");
  49. container.style.textAlign = "center";
  50. container.appendChild(button);
  51. sibling.insertBefore(container, sibling.firstElementChild);
  52. }
  53. }
  54. }
  55.  
  56. addRedirectButton();