AtCoder Zip Copy

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();

})();