Add Copy Button

Add a button that copy code to the clipboard

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Add Copy Button
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Add a button that copy code to the clipboard
// @author       beet
// @match       *://judge.u-aizu.ac.jp/onlinejudge/review.jsp*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
$(window).load(function() {
    $("#tab").append("<a  id=\"copy\" class=\"link\">Copy</a>");
    $("#tab").append("<a id=\"copyalert\" style=\"display:none;margin-left:100px;\">copied</a>");
    $("#tab").append("<div id=\"buf\"></div>");
    $('#copy').on('click', function(){
    let text = $("#code")[0].innerText;
        console.log(text);
    let buf = $('<textarea></textarea>');
    buf.text(text);
    $("#buf").append(buf);
    buf.select();
    document.execCommand('copy');
    buf.remove();
    $('#copyalert').show().delay(2000).fadeOut(400);
  });
  });
})();