AtCoder Zip Copy

AtCoderの問題文中の .zip リンクの横にコピーボタンを追加します。

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         AtCoder Zip Copy
// @namespace    https://github.com/e6nlaq/atcoder-zip-copy
// @version      1.0.0
// @author       e6nlaq
// @description  AtCoderの問題文中の .zip リンクの横にコピーボタンを追加します。
// @license      MIT
// @copyright    (C) 2026 e6nlaq
// @match        https://atcoder.jp/contests/*/tasks/*
// ==/UserScript==

(function () {
  'use strict';

  function init() {
    const taskStatement = document.getElementById("task-statement");
    if (!taskStatement) return;
    const links = taskStatement.querySelectorAll("a");
    for (const link of links) {
      const url = new URL(link.href, window.location.href);
      if (url.pathname.toLowerCase().endsWith(".zip")) {
        const btn = document.createElement("button");
        btn.type = "button";
        btn.textContent = "Copy";
        btn.className = "btn btn-default btn-sm";
        btn.style.marginLeft = "0.5em";
        btn.style.verticalAlign = "middle";
        btn.addEventListener("click", (e) => {
          e.preventDefault();
          navigator.clipboard.writeText(link.href).then(() => {
            const originalText = btn.textContent;
            btn.textContent = "Copied!";
            setTimeout(() => {
              btn.textContent = originalText;
            }, 1e3);
          });
        });
        link.parentNode?.insertBefore(btn, link.nextSibling);
      }
    }
  }
  init();

})();