New Userscripts

在 WZOI 中,给样例输入输出添加复制按钮。

当前为 2024-02-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         New Userscripts
// @namespace    http://tampermonkey.net/
// @description  在 WZOI 中,给样例输入输出添加复制按钮。
// @version      2024-02-18
// @author       chenbs
// @match        https://wzoi.cc/*
// @grant        none
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    // 复制字符串函数
    function copy(text){
        var input = document.createElement('textarea');
        input.setAttribute('id', 'input_for_copyText');
        input.value = text;
        document.getElementsByTagName('body')[0].appendChild(input);
        document.getElementById('input_for_copyText').select();
        document.execCommand('copy');
        document.getElementById('input_for_copyText').remove();
    }

    // 复制按钮
    var fa = document.getElementsByClassName("sample_io");
    for(let i=0; i<fa.length; i++){
        let cp = document.createElement("button");
        cp.innerText = "复制";
        cp.onclick = function(){let s=this.parentNode.innerText;copy(s.substr(0,s.length-3));};
        fa[i].appendChild(cp);
    }
})();