Copy Result

copy result to clipboad

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();
})();