clipboard-shims

Shims for GM_setClipboard and GM.setClipboard.

이 스크립트는 직접 설치해서 쓰는 게 아닙니다. 다른 스크립트가 메타 명령 // @require https://update.greatest.deepsurf.us/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;