drchloe / Xchan Gold Alpha

// ==UserScript==
// @name         Xchan Gold Alpha
// @version      0.0.1.4
// @description  Experimental script to enhance xchan.pw
// @include      https://xchan.pw/*
// @include      http://xchan.pw/*
// @require 	 https://cdn.jsdelivr.net/jquery.timeago/1.4.1/jquery.timeago.js
// @namespace    https://openuserjs.org/scripts/drchloe/Xchan_Gold_Alpha
// ==/UserScript==


//hideposts
function hidesystem(r){ if (r) {alert('Recarregue para desativar');} else {
    function hideposts(){$('.extrabtns').prepend('<div class="hidepost" style="display:inline-block;"><img src="https://xchan.pw/css/icons/blank.gif" border="0" class="hidethread" alt="hide"></div>');};
    if (localStorage.getItem("hidenposts")){var rawposts = localStorage.getItem("hidenposts"); var hidenposts = JSON.parse(rawposts);} else {var hidenposts = [];};

    hideposts();
    
    $(document).on('click', ".hidepost", function() { 
        id = $(this).parent().parent().attr('id');
        id = '#' + id;
        if ( hidenposts.indexOf(id) == -1) {hidenposts.push(id);
                                            localStorage.setItem("hidenposts", JSON.stringify(hidenposts))                                    
                                            $(this).parent().parent().attr('style', 'height:17px;overflow:hidden;');
                                           } else {
                                               hidenposts.splice(hidenposts.indexOf(id), 1);
                                               localStorage.setItem("hidenposts", JSON.stringify(hidenposts))                                    
                                               $(this).parent().parent().attr('style', 'height:auto;overflow:;');
                                           };    
    });

    $("<style>").text(""+hidenposts+"{height:17px;overflow:hidden;}").appendTo("head");

}};

//////////////////////////////////////////
var curver = '1';
if (localStorage.getItem("xgoldver") != curver) { localStorage.removeItem("xgoptions");localStorage.setItem("xgoldver", curver)}

$("<style>").text("iframe{display:inline-block;} .canfly{position:fixed;left:-600px;}.contentview {position:fixed;top:10px;left:-2048px;} iframe{display:inline-block;} .previewbox{position:fixed;bottom:10px;left:-150px;} .mbutton:hover{color:orange;width:100%;} .mbutton, .tbutton{cursor:pointer;cursor:hand;transition: color 0.5s ease;transition: width 0.5s ease;background: black;margin: 2px;padding: 2px;color: grey;font-size: 15px;font-weight: bold;    display: inline-block;    width: 90%;    font-family: monospace;} .tbutton{color:gold;font-size: 17px;width:100%;} .woptions{width:65px;height:63px;position:fixed;top:10px;right:30px;cursor:pointer;cursor:hand;transition: background-image 0.5s ease;} .selm{color:white;width:100%;} .wmenu{position:fixed;width:250px;height:900px;top:-900px;right:100px;background:grey;}").appendTo("head");

//Menu and Options System
//Images
var wrenchhover = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAAA/CAYAAAC/36X0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkL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Q2LhHJRQ7alpcUQACOGiMKx2ySjdXcqjJlAIEAtLS3Chqz6OYzqCWYKrTatMkeOHEmZIxRpj5v+6ENEC0jGoTpy5IgIfFsmqs2PqCfNycmhwcFBQwBsNpshPyDFz3+E/AibzWYIxODgIOXk5GjlP5KRajMDviHguej/+fn52LFjB2w2G8LhMDjnmJ+fx+DgoCFFBu9SOOV6+DFmSB1yOp3Iy8uLyV9eXsbQ0BCmp6fVen+rZu+n1XfgLPEHIQkYInvT/TYyYhF7H0Z+RO/MNF8iX8g2/68BSAcIq4TmjJM0Ip/puhkS78GcYTgZReZhO10KRyNnGE5C0Rm3SnCbfQGmfYJaEQDIP44N88vYGvG8YQBc4liwyfjr3CH8mKzrky4Ya7rx2HIQlaEwcqPyASzn2fD36WbcBACzOsRA+H8f/x0APz1K0QUaoCkAAAAASUVORK5CYII=';

var button = $('<div class="woptions"></div>').css("background-image", "url("+wrench+")");
$('body').append(button);

$(document).on('mouseenter', ".woptions", function () {
    $(this).css("background-image", "url("+wrenchhover+")");
});

$(document).on('mouseleave', ".woptions", function () {
    $(this).css("background-image", "url("+wrench+")");
});

//Menu
var menu = $('<div class="wmenu"><div class="tbutton">XGold:</div><br><br></div>');
var menuoptions = ['Catálogo', 'Backlinks', 'Formatador de Texto','Pré-exibir Imagens', 'Detector de Batatas','Trip Checkbox', 'Tempo Relativo', 'Exibir 50 posts', 'Fundir /e/', 'Mostrar títulos de Youtube', 'Meta Hovers', '403 pls go', 'OP como Título', 'Quickreply Melhorado', 'EzSpoiler', 'Esconder Posts'];

for (i = 0; i < menuoptions.length; i++) {
    $(menu).append('<div class="mbutton" id="m'+i+'">'+menuoptions[i]+'</div><br>');
}

$('body').append(menu);

$(document).on('click', ".woptions", function () {
    if ($(this).hasClass('wopen')){
        $('.wmenu').animate({top: "-900px", }, 1000 );
        $(this).removeClass('wopen');
    } else {
        $('.wmenu').animate({top: "0px", }, 1000 );
        $(this).addClass('wopen');
    }
});

$(document).on('click', ".mbutton", function () {
    if ($(this).hasClass('selm')){
        $(this).removeClass('selm');
        if (fun[$(this).attr('id')]){
            fun[$(this).attr('id')]('r');
        };
    }else{
        $(this).addClass('selm');
        if (fun[$(this).attr('id')]){
            fun[$(this).attr('id')]();
        };
    }

    saveoptions();
});

//OptionLoader
var activeoptions = "none,m1,m2,m3,m4,m5,m6,m9,m11,m13,m14,m12,m10,"; //Default Options

if (localStorage.getItem("xgoptions")) { activeoptions = localStorage.getItem("xgoptions");}
activeoptions = activeoptions.split(',');
for (n = 0; n < activeoptions.length; n++) {
    $('#'+activeoptions[n]+'').addClass('selm');
}

//OptionSaver
function saveoptions(){
    var ids = ["none"];
    $('.selm').each(function(){ids.push($(this).attr('id'))});
    localStorage.setItem("xgoptions", ids.toString())
}
saveoptions();

//Functions

//refresh roll

function roll(){
    $('.reply:contains("!roll")').each(function(){    
        var imgnum = $(this).parent().parent().find('.filesize').find('a').text();

        imgnum = parseInt(imgnum.split('.')[0]);    
        var roll = $(this).find('blockquote').html();
        var start = roll.indexOf('!roll') + 5;
        var dice = roll.substring(start, start + 5).trim();
        console.log(dice);
        if (dice.indexOf('d') > -1){        
            var dices = dice.split('d');
            var rolls = parseInt(dices[0]);        
            var sides = parseInt(dices[1]);
        } else {            
            var dice = "1d20";
            var rolls = 1;
            var sides = 20;
        }        
        if (rolls >= 3) { rolls = 3 };        
        for (i = 0; i < rolls; i++) {
            imgstr = ''+imgnum+'';
            multinum = imgnum;
            if (i > 0){multinum = imgnum * imgstr.slice(0, (8+i));};
            printnum = (multinum % sides) + 1;
            var col = "red";
            if (printnum >= (sides/2)) {col = 'yellow'};
            if (printnum >= ((sides/3)*2)) {col = 'green'};            
            $(this).append('<br><span class="rolls" style="padding:2px;display:inline-block;background:black;color:orange;">Rolagem '+dice+':<span style="color:'+col+';"> '+printnum+'</span></span>');
        };
    });
};

//Merge /e/

var ise = false;
var defboard = $('#quickform').find('input[name="board"]').attr('value');

$(document).on('mouseenter', '.ethread', function() {ise = true;});
$(document).on('mouseleave', '.ethread', function() {ise = false;});

$(document).on('click', ".quickreply", function() {
    if (ise) {
        $('#quickform').find('input[name="board"]').attr('value', 'e');
    } else {
        $('#quickform').find('input[name="board"]').attr('value', defboard);
    };
})



function todate(string){
    var a = string.split('@');
    var b = a[0].split('/');
    var c = a[1].split(':');
    tiem = new Date(b[2],b[1],b[0],c[0],c[1],'00');
    return tiem;
}

function mergee(){
    var boarde = ""
    $.get("https://xchan.pw/e/", function (data) {  
        boarde = data;
    }).done(function() {

        $(boarde).find('div[id*="thread"]').find("label:contains('@'):last").each(function() {
            tiem1 = todate($(this).clone().children().remove().end().text());
            var currentpost = $('<div class="ethread" style="border-right: orange solid 4px;"></div>').append($(this).parent().parent().parent().parent().parent().parent());
            currentpost.append('<hr>');
            $('div[id*="thread"]').find('.time:last').each(function(){
                tiem2 = todate($(this).attr('iso'));                

                var postthis = false;
                if (tiem1 > tiem2){
                    $(this).parent().parent().parent().parent().parent().parent().parent().before(currentpost);
                    console.log(""+tiem1+"-"+tiem2+"");
                    return false;
                };

            });
        });
        console.log('test');
    });
};



//Hijack Hovers m10
function metahover(r){
    if (r){
        alert('Recarregue para desativar.');
    } else {
        $("<style>").text(".reflinkpreview {display:none!important;} div[class^='floater'], .hold {min-width: 0; z-index: 9999; margin: 0 !important; display: block !important; max-width: 808.5px; background:grey; font-family: 'Trebuchet MS','Tahoma','Verdana','Arial',sans-serif; font-size: 13px; text-align: left;}").appendTo("head");

        $('.logo').append('<div class="previews"></div>');

        var waiter;
        var c;
        $(document).on('mouseenter', 'a[class^="ref|"]', function() {
            c = $(this).attr("class").split('|'); 
            var htop = $(this).offset().top;
            var hleft = $(this).offset().left;

            waiter = window.setTimeout(function() {

                $('.floater').attr('class', 'hold');

                var d = $("<div></div>").addClass('floater').attr({
                    style : "position:absolute;width:400px;"
                });

                if ($('#postform [name=board]').val() == c[1] && $('#reply' + c[3]).length && (($('#thumb' + c[3]).length && $('#thumb' + c[3] + " img:first-child").attr("src").lastIndexOf("thumb") != -1) || !$('#thumb' + c[3]).length)) {
                    var f = true;
                    d.html($("#reply" + c[3]).parents("table").html())
                } else {
                    d.html('Carregando...').toggle("normal");
                    $.get(ku_boardspath + '/read.php?b=' + c[1] + '&t=' + c[2] + '&p=' + c[3] + '&single', {}, function (a, b) {
                        if (b != "success") {
                            alert('wut')
                        } else {

                            if (a) {
                                d.html(a)
                            } else {
                                d.html(_("something went wrong (blank response)"))
                            }
                        }
                    })
                }

                $('.previews').append(d).slideDown( "slow" );
                //loop();

                if (f) {
                    //d.toggle("normal")
                };

                $('.floater')
                    .css("top", htop)
                    .css("left",(hleft-100))
            }, 500);
        });
        $(document).on('mouseleave', 'a[class^="ref|"]', function() { clearTimeout(waiter); });


        $(document).on('mouseleave', '.previews', function() {    

            $('.floater').remove();
            $('.hold').remove();
        });  

    };
};
//Nomes nos Quotes
function namequotes(r){
    if (r) {$('.dyn').remove();} else {

        $('a[onclick*="highlight"]').each(function() {
            if($(this).attr('class'))
            {        

                target = $(this).attr('class').split('|');
                nom = $('.reply[id*="'+target[3]+'"]').find('label').first().children().text();        
                var me = $(this);
                var tt = target[3];
                if (nom.length >= 1){

                    $(this).after('<div class="dyn" style="display:inline-block;color:green;"> - '+nom+'</div>');
                    $(this).addClass('named')
                } else {/*

            if (cache.indexOf(target[3]) >= 0){
                $(me).after('<div style="display:inline-block;color:green;"> - '+cache[target[3]]+'</div>');
            }else{
                console.log('downloading');
                var appender = "";
                 var t3 = target[3]
                $.get('https://xchan.pw/read.php?b='+target[1]+'&t='+target[2]+'&p='+target[3]+'&single', function (data) {
                    appender = $(data).find('label').first().children().text();
                    }).done(function() {                   
                    cache.push({t3appender})
                    $(me).after('<div style="display:inline-block;color:green;"> - '+appender+'</div>');
                    localStorage.setItem("quotecache", JSON.stringify(cache))
                });
            };
        */};
            };   
        });

        $(document).on('mouseenter', 'a[onclick*="highlight"]', function() {

            if($(this).not('.named').attr('class'))
            {        
                target = $(this).attr('class').split('|');
                nom = $('.reply[id*="'+target[3]+'"]').find('label').first().children().text();        
                var me = $(this);
                var appender = "";
                $.get('https://xchan.pw/read.php?b='+target[1]+'&t='+target[2]+'&p='+target[3]+'&single', function (data) {
                    appender = $(data).find('label').first().children().text();
                }).done(function() {
                    if (! $(me).next().hasClass('dyn'))
                    {
                        $(me).after('<div class="dyn" style="display:inline-block;color:green;"> - '+appender+'</div>');
                    };
                });

            };
        });
    };
};
//Hijacks//Quick Reply Replacer
$('#qr_form').draggable();

$(document).mousemove(function (e) {
    window.pageX = e.pageX;
    window.pageY = e.pageY;
});
function getSelectedText() {
    if (window.getSelection) {
        return window.getSelection().toString();
    } else if (document.selection) {
        return document.selection.createRange().text;
    }
    return '';
};

$(document).on('click', ".qrp", function() {
    tidrpt = $(this).attr('title');
    tidrpts = tidrpt.split(' ');
    var threadid = tidrpts[0];
    var replyto = tidrpts[1];

    var meval = "";
    $('#qr_info').html("Reposta ao post: " + replyto + " na thread: " + threadid);
    $('#qr_name').val($.cookie("name"));
    $('#qr_postpassword').val($.cookie("postpassword"));
    $('#qr_threadid').val(threadid);
    //meval += $('#qr_message').val();
    //leval = $('textarea[name="message"]').val();
    //$('textarea[name="message"]').val('');
    var text = getSelectedText();
    if (text!='') {
        text = text.split('\n');
        var ftext = "";

        text.forEach(function (str) {
            if (str !== '') {
                str = '>' + str + '\n';
            } else {
                str = '\n';
            }
            ftext += str;});

        $('#qr_message').insertAtCaret('', ">>" + replyto + "\n" + ftext);
    } else {
        $('#qr_message').insertAtCaret('', ">>" + replyto + "\n");
    };
    //$("#qr_message")[0].value += '>>' + replyto + '\n';
    //citeReply(replyto);
    //$('#qr_message').val(meval + ">>" + replyto + "\n");

    $('#qr_form').css({
        'left' : window.pageX,
        'top' : window.pageY,
        'display' : 'block'
    }).fadeIn('slow');
    $('#qr_name').get(0).type = 'password';

    $( '.namecheck' ).appendTo( '.qr_new' );
    $('.postblock:contains("Mensagem"):eq(1)').append($('.movepreview'));
});
$(document).on('click', "img[alt='Close']", function() {
    $( '.namecheck' ).appendTo( '.new' );
});

function prepqrp(r){
    if (r) {alert('Recarregue para desativar.')} else {
        $('a[title="Resposta Rápida"]').each(function() {	
            var onc = $(this).attr('onclick');
            oncf = onc.replace('javascript:qr(','').replace(',', '').replace(');', '');
            $(this).attr('onclick', '');    
            $(this).attr('title', oncf);
            $(this).attr('class', 'qrp');

        });
    };
};


// OP como Titulo
var oldtitle = $(document).prop('title')

function optitle(r){

    if (r){
        $(document).prop('title', oldtitle);
    }else{
        var ur = ''+document.location+'';
        if (ur.indexOf("res") >= 0){
            text = $('blockquote').first().text();
            $(document).prop('title', 'Xchan -'+text+'');
        }
    };
};
//EzSpoiler
var ezsp = false;
function ezspoiler(r){
    if (r) 
    {
        ezsp = false;
    } 
    else 
    {
        ezsp = true;
    };
};

$(document).on('click', ".postfix, input[value=\"Enviar\"]", function() {
    if (ezsp)
    {
        var test = $('#qr_message').val();
        var isEven = function (x) {
            return !(x & 1);
        };

        var matches = test.match(/\*\*/g);
        if (matches)
        {

            if (matches.length >= 2 && isEven(matches.length))
            {
                for (i = 0; i < matches.length; i++) {
                    if (isEven(i)) {
                        test = test.replace(/\*\*/, "[spoiler]");
                    } else {
                        test = test.replace(/\*\*/, "[/spoiler]");
                    };
                };
                $('#qr_message').val(test);
            };
        };
    };
});


//403 fixer
function vai(r){
    if (r){
        $('.postfix').replaceWith('<input type="submit" value="Enviar" accesskey="z">');
    } else {
        $('#quickform, #postform').find('input[accesskey="z"]').replaceWith('<input type="button" class="postfix" value="[Enviar]">');
    };
};


function postfix(form){ 
    $('<iframe />').attr('src', 'https://xchan.pw/b/').attr('style', 'width:10px;height:10px;').appendTo('body');    
    setTimeout(function(){document.forms[form].submit();}, 3000); 
}; 

$(document).on('click', ".postfix", function() {
    postfix($(this).closest('form').attr('name'));
    $(document).prop('title', 'Xchan - Postando...');
    $(this).attr('value', 'Postando...');
}); 



//floatcontent
function float(){

    $('.thumb').each(function(){
        url = $(this).parent().parent().attr('href');
        $(this).parent().unwrap().wrap('<div class="nthumb" href="'+url+'" style="cursor: pointer; cursor: hand;"></div>');
    });
    $('.filesize').find('a').attr('onclick', '').attr('target', '_blank');
}



$(document).on('click', ".nthumb", function () {
    if ($(this).attr('href').indexOf('.webm') >= 1){
        var content = $('<div class="contentview"></div>')    
        $(content).css('left', '-2000px').html('').append('<div class="fimg" style="cursor: pointer; cursor: hand;color:grey;background-color:black;font-weight:bold;font-family: monospace;    font-size: 15px;    display: inline-block;    float: right;">[Fechar]</div><br><video src="'+$(this).attr('href')+'" loop controls style="min-width:50px;min-heigth:50px;max-width:99%;max-height:99vh;">').animate({left: "10px", }, 1000 );
        $('body').append(content);
    } else{
        var content = $('<div class="contentview"></div>')    
        $(content).css('left', '-2000px').html('').append('<img class="fimg" src="'+$(this).attr('href')+'" style="min-width:50px;min-heigth:50px;max-width:99%;max-height:99vh;background-color: rgba(196, 196, 196, 0.5);">').animate({left: "10px", }, 1000 );
        $('body').append(content);
    };
    $('.contentview').draggable();
});

$(document).on('click', ".fimg", function () {
    //$(this).parent().animate({left: "-2000px", }, 1000 );
    //setTimeout("$(this).parent().remove()", 1000)
    $(this).parent().remove();
});

//TimeAgo

function reltime(r) {
    if (r){
        $('.time').remove();
    } else {
        $('.time').remove();
        $( "label:contains('@')" ).each(function() {
            var vovar = $(this).contents().map(function() {
                if( this.nodeType === 3 ) {
                    return this.data;
                }
            }).get().join('');

            vovar1 = vovar.split("@");
            vovardate = vovar1[0].split("/");
            vovaryear = vovardate[2].split(" ");
            vovarmonth = vovardate[1] - 1;
            vovartime = vovar1[1].split(":");
            tiem = new Date(vovaryear[0], vovarmonth, vovardate[0], vovartime[0], vovartime[1])
            tiemiso = tiem.toISOString();
            tiemago = jQuery.timeago(tiemiso);
            $( this ).append( '<span iso="'+vovar+'" class="time">( <bold>' + tiemago + ' </bold>)</span>' );
        });    
    };
};




//Detector de Batatas


function batata(r){ 
    if (r){
        $('.reply').css('background-image', '');
    } else {
        $('.postername:contains("Semi"), .postername:contains("Se‭‭mi")').parent().parent().css('background-image', 'url(\"http://a.pomf.se/rcqfit.png\")');
        $('.postertrip:contains("hKvr")').parent().parent().css('background-image', 'url(\"http://a.pomf.se/ndnvht.png\")');
        $('blockquote:contains("…"), blockquote:contains("daí"), blockquote:contains("Coë")' ).parent().css('background-image', 'url(\"http://a.pomf.se/aopqpg.jpg\")');
    };
}; 

//Catalogo
$("<style>").text(".catalogimg > img {max-width:100%;max-height:100%;} .catalogitem {margin-bottom:10px;}").appendTo("head");

function catalog(r){
    if (r){
        $('.catalog').remove();
    } else {
        $('.catalog').remove();
        $('body').prepend('<div class="catalog" style="background: dimgray;border: solid 1px;overflow-y:scroll;overflow-x:hidden;width:240px;height:650px;position:fixed;top:100px;left:-300px;"><table id="catalogt"><tbody><div class="closecat hov" style="font-size: 15px;font-weight: bold;position:fixed;top:80px;left:10px;color:red;font-size:11px;cursor: pointer; cursor: hand;">Abrindo catálogo...</div></tbody></table></div>');
        $.get("https://xchan.pw/b/catalog.html", function (data) {
            $(data).find('a[class^="ref|"]').each(function () {
                var href = $(this).attr('href');
                var c = $(this).attr("class").split('|'); 
                var d = $("<span></span>").addClass('catalogimg').attr({
                    style : "max-width:220px;background:#F7F7F7;"
                });
                var g = $("<div></div>").addClass('catalogtext').attr({
                    style : "overflow-x:hidden;overflow-y:scroll;max-height:200px;max-width:220px;background:#F7F7F7;"
                });
                $.get(ku_boardspath + '/read.php?b=' + c[1] + '&t=' + c[2] + '&p=' + c[3] + '&single', {}, function (a, b) {
                    if (b != "success") {
                        alert('wut')
                    } else {

                        if (a) {
                            var z = $('<img />').html(a).find('.thumb').removeClass();
                            var y = $('<blockquote>').html(a).find('blockquote');                        

                            d.html(z);
                            g.html(y);
                            $('.catalog').animate({left: "5px", }, 1000 );
                            $('.closecat').remove();

                        } else {
                            d.html(_("something went wrong (blank response)"))
                        }
                    }
                })       




                var wrap = $("<div></div>").addClass('catalogitem').append(d).wrapInner('<a href='+ href +'>').append(g);
                $('#catalogt').append(wrap);

            });

        });
        $('#catalogt').prepend('Busca:<input type="text" name="catsearch" size="20" maxlength="75" class="catsearch">');
    };
};

$.extend($.expr[':'], {
    'containsi': function(elem, i, match, array)
    {
        return (elem.textContent || elem.innerText || '').toLowerCase()
            .indexOf((match[3] || "").toLowerCase()) >= 0;
    }
});


$(document).on('keypress', ".catsearch", function() {
    if ($(this).val()) {
        $('.catalogitem').show();
        $('.catalogitem').not(':contains("'+$(this).val()+'")').hide();
    }else{
        $('.catalogitem').show();
    };
});

//Text Formatting
jQuery.fn.extend({
    insertAtCaret: function(myValue, myValueE){
        return this.each(function(i) {
            if (document.selection) {
                //For browsers like Internet Explorer
                this.focus();
                sel = document.selection.createRange();
                sel.text = myValue + myValueE;
                this.focus();
            }
            else if (this.selectionStart || this.selectionStart == '0') {
                //For browsers like Firefox and Webkit based
                var startPos = this.selectionStart;
                var endPos = this.selectionEnd;
                var scrollTop = this.scrollTop;
                this.value = this.value.substring(0,     startPos)+myValue+this.value.substring(startPos,endPos)+myValueE+this.value.substring(endPos,this.value.length);
                this.focus();
                this.selectionStart = startPos + myValue.length;
                this.selectionEnd = ((startPos + myValue.length) + this.value.substring(startPos,endPos).length);
                this.scrollTop = scrollTop;
            } else {
                this.value += myValue;
                this.focus();
            }
        })
    }
});

function textformat(r){
    if (r){
        $('.stylebar, .sb').remove();
    } else {
        $('textarea[id="qr_message"]').after('<br class="stylebar">');
        $('.stylebar').after('<input class="formbutton_SS sb" type="button" value="Spoiler" /><input class="formbutton_B sb" type="button" value="B" /><input class="sb formbutton_R" type="button" value=">" /><input class="sb formbutton_S" type="button" value="S" /><input class="sb formbutton_I" type="button" value="I" /><input class="sb formbutton_C" type="button" value="Code" />');
        $('.formbutton_I').css('font-style', 'italic');
        $('.formbutton_S').css('text-decoration', 'line-through');
        $('.formbutton_R').css('color', 'green');
        $('.formbutton_B').css('font-weight', 'bold');
        $('.formbutton_SS').css('font-weight', 'bold');
    };


    $('.formbutton_C').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret("[code]", "[/code]");
    });
    $('.formbutton_I').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret("[i]", "[/i]");
    });
    $('.formbutton_S').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret("[s]", "[/s]");
    });
    $('.formbutton_R').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret(">", "");
    });
    $('.formbutton_B').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret("[b]", "[/b]");
    });

    $('.formbutton_SS').on('click', function(){ 
        $('textarea[id="qr_message"]').insertAtCaret("[spoiler]", "[/spoiler]");
    });
};

//Tripbox
function tripbox(r){
    if (r){
        $( '#qr_name, input[name="name"]:first' ).unwrap();
        $('.new, .qrnew, .namecheck').remove();
        //$('#qr_name, input[name="name"]').get(0).type = 'text';

    }else{


        $( 'input[name="name"]:first' ).wrap( '<span class="new"></span>' );
        $( '#qr_name' ).wrap( '<span class="qr_new"></span>' );
        $( '.new' ).append( '<input type="checkbox" class="namecheck" value="Bike" checked="checked">' );
        if (localStorage.getItem("namecheck") === null) {}else{$( ".namecheck" ).prop( "checked", false ); $( 'input[name="name"], #qr_name' ).prop('disabled',true);};

        $(document).on('change', ".namecheck", function() {
            if ( $( '.namecheck' ).prop( "checked" ) ) {$( 'input[name="name"], #qr_name' ).prop('disabled',false); localStorage.removeItem('namecheck');}else{$( 'input[name="name"], #qr_name' ).prop('disabled',true); localStorage.setItem('namecheck', '');};
        });
    };
};

//Backlinks

function showpreview(r){
    if (r){
        $('.previewbox').remove();
        //$('.spreview-area').attr('class', 'preview-area').attr('id', 'preview-form')
    } else {
        $('.preview-area').css('display', 'none !important').attr('class', 'spreview-area').attr('id', 'spreview-form');
        $('.previewbox').remove();
        $('body').append('<div class="previewbox"></div>');
    };
};

$('input[name="imagefile"]').change(function () {
    if ($('#m3').hasClass('selm')){
        $('.previewbox').css('left', '-150px');
        $('.previewbox').animate({left: "50px", }, 1000 );
        if (window.FileReader) {
            var Reader = new FileReader();
            var file = this.files[0];
            window.file2 = file;
            var previewarea = $('.previewbox');

            if (file.type.indexOf("video") > -1) { 

                previewarea.html('');                
                Reader.onload = function (event) {
                    previewarea.append([' <video width="200" height="200" autoplay muted controls loop><source src="'+ event.target.result +'" type="'+ window.file2.type +'">Your browser does not support the video tag.</video>'].join(''));
                }
                Reader.readAsDataURL(file);    

            } else {

                previewarea.html('');
                Reader.onload = function (event) {
                    previewarea.show().append(['<img style="max-height:200px;max-width:200px;" src="' + event.target.result + '" alt="">'].join(''));
                }
                Reader.readAsDataURL(file);
            };
        }

    };

});

function backlinks(r) {
    if (r){
        $('.protect').removeClass('protect');
        $('a[rem="1"]').remove();
    }else{
        $('#delform').find(".reply").not('.protect').each(function() {
            blink($(this));
        });
        $('.floater, .hold').find(".reply").not('.protect').each(function() {
            blink($(this));
        });
    };
};

function blink(t){   
    t.addClass('protect');
    rid = t.attr('id').replace('reply','');
    datas = t.find('.reflink').find("a:nth-child(2)").attr('href');
    t.find("a[class^='ref|']").each(function() {
        var quoted = $(this).text();            
        quoteds = quoted.replace('>>','');
        backquote(quoteds, rid, datas);
    });   
};

function backquote(quoteds, rid, datas){    
    splicer = datas.replace('.html#i','/');    
    splicer2 = splicer.split('/');
    $(".reflink:contains('" +quoteds+ "')").after('<a rem="1" href="/'+splicer2[1]+'/res/'+splicer2[3]+'.html#'+rid+'" onclick="return highlight(\''+rid+'\', true);" class="ref|'+splicer2[1]+'|'+splicer2[3]+'|'+rid+'">&gt;&gt;'+rid+'</a>');

};

// Youtube Title Loader

$(document).on('mouseenter', 'a[href*="youtube.com/watch?"], a[href*="youtu.be"]', function() {
    if ($('#m9').hasClass('selm')){
        url = extractVideoID($(this).attr('href'));
        $(this).replaceWith('<iframe src="https://www.youtube.com/v/'+url+'" width="300px" height="25px" ></iframe><div class="mask" style="display:inline-block;">OPEN </div>');
    };
});


function extractVideoID(url){
    var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
    var match = url.match(regExp);
    if ( match && match[7].length == 11 ){
        return match[7];
    }else{
        return url;
    }
}

$(document).on('click', ".mask", function() {
    $('<br><div class="vp canfly" style="cursor: pointer; cursor: hand;display:inline-block;background:grey;height:500px;"></div>').appendTo('.logo');
    $(this).prev().clone().attr('height', '480x').attr('width', '600px').appendTo('.vp');
    $('.vp').prepend('<div class="killvid" style="background:orange;display:inline;">[Fechar]</div><br>');
    //    jQuery('html,body').animate({scrollTop:0},0);
    $('.vp').animate({left: "10px", }, 1000 ).draggable();

}); 

$(document).on('click', ".killvid", function() {
    $(this).parent().remove();
    $(this).remove();
}); 



//Save functions in Array
var fun = {
    m8:mergee,
    m1:backlinks,
    m5:tripbox,
    m3:showpreview,
    m2:textformat,
    m0:catalog,
    m4:batata,
    m6:reltime,
    m11:vai,
    m12:optitle,
    m13:prepqrp,
    m14:ezspoiler,
    m10:metahover,
    m15:hidesystem
}

function start(){
    $('.selm').each(function(){
        if (fun[$(this).attr('id')]){
            fun[$(this).attr('id')]();
        };
    });
    float();
};
start();

var funloop = {
    m8:mergee,
    m1:backlinks,
    m4:batata,
    m6:reltime,
    m13:prepqrp,
    m15:hidesystem

};

//Run All Active Options
function loop(){
    $('.selm').each(function(){
        if (funloop[$(this).attr('id')]){
            funloop[$(this).attr('id')]();
        };
    });
    float();
    roll();
};
//loop();
//Default Stuff

//Protect Trip
$('input[name="name"]').get(0).type = 'password';

$( 'input[name="name"]' ).focus(function() {
    $('#qr_name, input[name="name"]').get(0).type = 'text';
});

$( 'input[name="name"]' ).focusout(function() {
    $('#qr_name, input[name="name"]').get(0).type = 'password';
});


//Live Index

//live index

var window_focus;

$(window).focus(function() {
    window_focus = true;
    unnotify();
    console.log('focus');
})
    .blur(function() {
    window_focus = false;
    console.log('unfocus');
});


function unnotify(){
    $('link[href*="favicon"]').remove()
    $('#favicon').remove();
    $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
    console.log('unotify');
};
unnotify();

function notify(){
    if (window_focus){unnotify();}else{
        $('#favicon').remove();
        $('head').append('<link href="https://i.imgur.com/TirPmur.png" id="favicon" rel="shortcut icon">');
        console.log('notify');
    };
};
//JavaReset

function loadjscssfile(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
        }

function javareset(){
    $('script[src*="xchan.js"], script[src*="kusaba.js"]').remove();
    loadjscssfile("https://xchan.pw/lib/javascript/kusaba.js", "js")
    loadjscssfile("https://xchan.pw/lib/javascript/xchan.js", "js")
    //$('head').append('<script type="text/javascript" src="https://xchan.pw/lib/javascript/kusaba.js"></script>');
    //$('head').append('<script type="text/javascript" src="https://xchan.pw/lib/javascript/xchan.js"></script>');
};



//Updater
var highest = -Infinity;
var compareme = 99999999999999999;
window.updateid = "";
window.updata = 0;
function initupdate(){    
    var highest = -Infinity;
    $('#delform').find("input[name='post[]']").each(function() {
        splice = $(this).attr('value');
        numb = parseInt(splice)
        highest = Math.max(highest, parseFloat(numb));        
    });
    return highest;
};

initupdate();
/*
$('#delform').before('<table><td class="be"></td><td class="ee"></td></table>');
$('.be').append($('#delform'));

$.get("https://xchan.pw/e/", function (data) {  
    $('.ee').append($(data).filter("#delform"));
});*/


function update(){
    var compareme = 0;    
    $.get("" + document.location, function (data) {        

        $(data).find("input[name='post[]']").each(function() {
            splice = $(this).attr('value');
            numb = parseInt(splice)
            compareme = Math.max(compareme, parseFloat(numb));
            window.updateid = compareme;
        });
        if (window.updateid > initupdate()){
            window.updata = data;
        };

    }).done(function() {
        if (! window.updata == 0){
            $("#delform").replaceWith($(window.updata).filter("#delform"));
            if (! window_focus){notify();};
            loop();
            javareset()
            window.updata = 0;
        };
    });
};



setInterval(function () { 
    update();
}, 10000);