Shims for GM_setClipboard and GM.setClipboard.
此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/483593/1304472/clipboard-shims.js
// ==UserScript== // @name clipboard-shims // @description Shims for GM_setClipboard and GM.setClipboard. // @author Jason Kwok // @namespace https://jasonhk.dev/ // @version 1.0.0 // @license MIT // ==/UserScript== let GM_setClipboard = function GM_setClipboard(data, type = "text/plain") { if (navigator.clipboard?.write) { navigator.clipboard.write([new ClipboardItem({ [type]: data })]); } else { document.addEventListener("copy", (event) => { event.preventDefault(); event.stopImmediatePropagation(); event.clipboardData.setData(type, data); }, { capture: true, once: true }); document.execCommand("copy"); } } GM.setClipboard = GM_setClipboard;