yosupo judge copy button

yosupo judgeのサンプルinputにコピーボタンをつけます。

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name     yosupo judge copy button
// @version  1
// @grant    none
// @author   tomboftime
// @namespace https://twitter.com/tomboftime
// @description yosupo judgeのサンプルinputにコピーボタンをつけます。
// @match    https://judge.yosupo.jp/problem/*
// @require  https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js
// ==/UserScript==
new ClipboardJS('.btn');

var pres = document.getElementsByTagName('pre'); 

for (var i = 0; i < pres.length; i++) {
  var pre = pres[i];
  if (pre.childElementCount == 0){
   //console.log(pre);
   var data = pre.childNodes[0].data;
   //console.log(data);
   var button = document.createElement("button");
   button.className = 'btn';
   button.innerHTML = "copy";
   button.setAttribute("data-clipboard-text",data);
    pre.parentNode.insertBefore(button, pre);
  }
}