ObrazekZeSchowka

ObrazekZeSchowka - Umożliwia wklejanie obrazku bezpośrednio z systemowego schowka podczas dodawania grafiki do wpisu na mirko lub w komentarzu

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         ObrazekZeSchowka
// @namespace    fuuYeah
// @version      0.2.6
// @description  ObrazekZeSchowka - Umożliwia wklejanie obrazku bezpośrednio z systemowego schowka podczas dodawania grafiki do wpisu na mirko lub w komentarzu
// @author       @fuuYeah / Lukasz Kowalski
// @match        https://www.wykop.pl/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function(){
    function defer(method) {
        if (window.$) {
            method();
        } else {
            setTimeout(function () {
                defer(method)
            }, 200);
        }
    }

    function initScript() {
        console.log('ObrazekZeSchowka initialised and waiting for paste events');
        $(document).on('paste', '.addMediaOverlay .embedUrl', function (event) {
            var items = (event.clipboardData || event.originalEvent.clipboardData).items;

            for (var i in items) {
                var item = items[i];

                if (item.kind === 'file') {
                    var blob = item.getAsFile(),
                        form = new FormData(),
                        hash = wykop.params.hash,
                        url = 'https://www.wykop.pl/ajax2/embed/upload/hash/' + hash,
                        xhr = new XMLHttpRequest();

                    form.append('mf_file_undefined', blob, "wykop_pl_dodatki ObrazekZeSchowka.png");
                    form.append('file_element', 'mf_file_undefined');
                    form.append('hash', hash);

                    xhr.onreadystatechange = function () {
                        if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                            var r = JSON.parse(xhr.responseText.replace('for(;;);', ''));

                            for (var i in r.operations) {
                                if (r.operations[i].type === 'callback') {
                                    var fn = wykop[r.operations[i].method];
                                    if (typeof fn === 'function') {
                                        fn($('.addMediaOverlay form'), r.operations[i].data);
                                    }
                                }
                            }
                        }
                    }

                    xhr.open("POST", url);
                    xhr.setRequestHeader("X-Requested-With", 'XMLHttpRequest');
                    xhr.send(form);
                }
            }
        })
    }

    defer(initScript);
})();