clipboardData Emulator

emulate clipboardData in non-IE browser

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name       clipboardData Emulator
// @namespace  com.ayanamist.clipboardData
// @version    0.4
// @description  emulate clipboardData in non-IE browser
// @include http*
// @run-at         document-start
// @grant unsafeWindow
// ==/UserScript==

(function () {
    'use strict';
    if (unsafeWindow.window.clipboardData) {
        return;
    }
    var textareaId = 'clipboardEmu';
    unsafeWindow.window.clipboardData = {
        clearData: function () {
            return true;
        },
        getData: function () {
            return '';
        },
        setData: function (format, data) {
            // Prevent multiple textarea instance.
            var clipboard = document.getElementById(textareaId);
            if (!clipboard) {
                clipboard = document.createElement("textarea");
                clipboard.style.float = 'left';
                clipboard.style.position = 'fixed';
                clipboard.style.left = 0;
                clipboard.style.top = 0;
                clipboard.style.width = '400px';
                clipboard.style.height = '300px';
                clipboard.style.zIndex = 9999;
                clipboard.id = textareaId;
                clipboard.readOnly = true;
                document.getElementsByTagName('body')[0].appendChild(clipboard);
            }
            clipboard.textContent = data;
            clipboard.focus();
            clipboard.select();
            var closeClipboard = function () {
                clipboard.parentNode.removeChild(clipboard);
                clipboard = null;
            };
            clipboard.onkeydown = function (evt) {
                if(evt.which == 27){ // Esc
                    closeClipboard();
    			}
            };
            clipboard.oncut = clipboard.oncopy = function () {
                setTimeout(closeClipboard, 0);
                return true;
            };
            return true;
        },
        files: [],
    };
})();