clipboardData Emulator

emulate clipboardData in non-IE browser

16.05.2014 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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: [],
    };
})();