您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
替换Discuz论坛的"点此复制到剪贴板"flash
当前为
// ==UserScript== // @name replace copy flash on Discuz // @name:zh-CN 替换Discuz的复制flash // @description replace the "click here to copy" flash on Discuz // @description:zh-CN 替换Discuz论坛的"点此复制到剪贴板"flash // @namespace https://github.com/Testla // @version 0.9.0 // @include http://www.tsdm.me/* // @include https://www.tsdm.me/* // @author Testla // @license MIT License // @compatible firefox 57 + Greasemonkey4/Tampermonkey tested // @compatible chrome + Tampermonkey // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js // @grant GM.info // @grant GM.setClipboard // @grant GM_info // @grant GM_setClipboard // @grant unsafeWindow // ==/UserScript== (function() { 'use strict'; // There are two versions available, // the non-privileged version doesn't use privileged API // but doesn't support Greasemonkey 4+ // and may be incompatible with some old browsers // (check https://developer.mozilla.org/en-US/docs/Web/API/document/execCommand#Browser_compatibility). // To switch to the non-privileged version: // 1. remove all @require and @grant in the header // 2. add @grant none to the same place // 3. comment out the privileged version and uncomment the non-privileged version // ---------------- BEGIN PRIVILEGED VERSION ---------------- // If you only run on Greasemonkey 4+, you can remove the @require. // If you need not to run on Greasemonkey 4+, // you can remove the @require line together with the following two lines // and replace all "GM." with "GM_". // Note that the "@grant GM_*"s are required for Tampermonkey in Chrome. function copyAndHint(text) { GM.setClipboard(text); // showPrompt comes with Discuz unsafeWindow.showPrompt(null, null, 'Copied', 3000); } function setCopy(text, hint) { copyAndHint(text); } function copycode(code_div) { copyAndHint(code_div.textContent); } var greasemonkey4OrGreater = GM.info.scriptHandler == 'Greasemonkey' && parseFloat(GM.info.version) >= 4.0; if (greasemonkey4OrGreater) { // uses Firefox-specific hack // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts exportFunction(copyAndHint, window, {defineAs:'copyAndHint'}); window.eval( 'window.setCopy = function(text, hint) { copyAndHint(text); };' + 'window.copycode = function(code_div) { copyAndHint(code_div.textContent); };'); } else { unsafeWindow.setCopy = setCopy; unsafeWindow.copycode = copycode; } // ---------------- END PRIVILEGED VERSION ---------------- // ---------------- BEGIN NON-PRIVILEGED VERSION ---------------- // var copyTextarea = document.createElement("textarea"); // copyTextarea.style.width = "0px"; // copyTextarea.style.height = "0px"; // copyTextarea.style.position = "fixed"; // // https://stackoverflow.com/questions/400212 // function copyAndHint(text) { // document.body.appendChild(copyTextarea); // copyTextarea.textContent = text; // copyTextarea.select(); // try { // var successful = document.execCommand('copy'); // var msg = successful ? 'succeeded' : 'failed'; // showPrompt(null, null, 'Copy ' + msg, 3000); // } catch (err) { // showPrompt(null, null, 'Oops, unable to copy', 3000); // console.log(err); // } // document.body.removeChild(copyTextarea); // } // window.setCopy = function(text, hint) { // copyAndHint(text); // }; // window.copycode = function(code_div) { // copyAndHint(code_div.textContent); // }; // ---------------- END NON-PRIVILEGED VERSION ---------------- console.log('finished replacing Discuz\'s copy flash'); })();