Copy Result

copy result to clipboad

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Copy Result
// @description  copy result to clipboad
// @version      0.2
// @author       harurun
// @match        https://wandbox.org/*
// @grant        none
// @license MIT
// @namespace Wandbox
// ==/UserScript==

(function() {
    'use strict';
    function copy(){
        let target=document.getElementsByClassName("wb-result-stdout")[0];
        if(navigator.clipboard){
            try{
                navigator.clipboard.writeText(target.textContent);
            }catch(e){
                console.log(e);
                alert("stdout is empty.");
            }
        }else{
            console.log("navigator is not exist.");
        }
    }
    // https://greasyfork.org/ja/scripts/434033-atcoder-title-copy/code ここから拝借してきました
    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
    async function notifyCopied(a) {
        a=this.name;
        a.textContent = "Copied!";
        await sleep(1500);
        a.textContent = "Copy";
    };
    async function create_btn(){
        await sleep(1500);
        let pars=document.getElementsByClassName("btn btn-primary");
        //console.log(pars,pars.length);
        let par=pars[pars.length-1].parentElement;
        let a=document.createElement("a");
        a.textContent="Copy";
        a.setAttribute("class","btn btn-primary");
        par.appendChild(a);
        a.addEventListener('click',copy,false);
        a.addEventListener('click',{name:a,handleEvent:notifyCopied});
    }
    create_btn();
})();