console.log("Custom Image Uploader - v " + args_uploader.current_version);

var semaforo_binding_upload = 0;


jQuery(document).bind('DOMSubtreeModified', function () {
    let href_obj_rimozione_img = jQuery('#remove-post-thumbnail');

    if(href_obj_rimozione_img.length > 0 && args_uploader.can_user_upload != 1){

        jQuery(href_obj_rimozione_img).on('click',() => {
            let time_out_2 = setTimeout(() => {
                if(semaforo_binding_upload == 0)
                    bindUploadClick();
                clearTimeout(time_out_2);
            },100);
        });

    }   

 });

jQuery(document).ready(() => {
    if(args_uploader.can_user_upload != 1)
        bindUploadClick();
});

function bindUploadClick(){
    semaforo_binding_upload = 1;
    jQuery('#set-post-thumbnail').on('click',() => {

        let time_out = setTimeout(() => {
            jQuery('#menu-item-upload').hide();
            jQuery('#menu-item-instantimages').click();
            clearTimeout(time_out);
        },500);

    });
}