- // ==UserScript==
- // @name Xchan Gold Alpha
- // @version 0.0.0.2
- // @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
- // @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js
- // @namespace https://greasyfork.org/users/2657
- // ==/UserScript==
-
- //Hijacks
-
- //Hijacks//Location hack
- function expandthread(){};
- function addpreviewevents(){};
- hijack = expandthread;
- hijack2 = addpreviewevents;
-
- location.replace("javascript:"+ hijack +"");
-
-
- //Hijacks//Quick Reply Preview Image
-
- $("[name='imagefile']:eq(1)").change(function () {
- if (window.FileReader) {
- var Reader = new FileReader();
- var file = this.files[0];
- window.file2 = file;
- var previewarea = $('.qrpreviewer');
-
- if (file.type.indexOf("video") > -1) {
-
- previewarea.html('');
- Reader.onload = function (event) {
- previewarea.append([' <video width="100" height="88" controls><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:88px;max-width:100px;" src="' + event.target.result + '" alt="">'].join(''));
- }
- Reader.readAsDataURL(file);
- };
- }
- });
-
- //Hijacks//Quick Reply Replacer
- $('#qr_form').draggable();
-
- $(document).mousemove(function (e) {
- window.pageX = e.pageX;
- window.pageY = e.pageY;
- });
-
- $(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();
- $('#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(){
- $('a[title="Resposta Rápida"]').each(function() {
- var onc = $(this).attr('onclick');
- oncf = onc.replace('javascript:qr(','').replace(',', '').replace(');', '');
- //oncfs = oncf.split(' ');
- $(this).attr('onclick', '');
- $(this).attr('title', oncf);
- $(this).attr('class', 'qrp');
- });
- };
-
- //Hijacks//Expand Thread
- $(document).on('click', ".expandthread", function() {
- var tid = $(this).parent().attr('onclick');
- tids = tid.split("'");
- var c = tids[1];
- var d = tids[3];
-
- var e = $("#replies" + c + d);
- if (e.length) {
- e.prepend(_('Expanding thread') + '...<br /><br />');
- e.load(ku_boardspath + '/expand.php?board=' + d + '&threadid=' + c, {}, function (a, b) {
- if (!a) {
- e.html(_("something went wrong (blank response)"))
- }
- if (b == "error") {
- alert(_('Something went wrong...'))
- }
- delandbanlinks(this);
- loop();
- })
- }
- return false
- });
-
-
- //Hijacks//Hover
-
- $("<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>');
-
- $(document).on('mouseenter', 'a[class^="ref|"]', function() {
-
- $('.floater').attr('class', 'hold');
- var c = $(this).attr("class").split('|');
- 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",$(this).offset().top)
- .css("left",($(this).offset().left-100))
-
- });
-
- $(document).on('mouseleave', '.previews', function() {
- $('.floater').remove();
- $('.hold').remove();
- });
-
-
- //Start
- $( document ).ready(function() {
- loop();
- $('#favicon').remove();
- $('link[rel="shortcut icon"]').remove();
- $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
-
- //addpreviewevents2();
- $('#qr_form').find('.postblock:contains("Mensagem")').append('<div class="qrpreviewer"></div>');
- $('.qrpreviewer').attr('style', 'background:none; border:0px; width:100px; padding:0px; position:relative; ');
- });
-
- window.dt = "";
-
-
- //Menu
-
- $(".navbar").after("<div class='optionslink hov' style='display:inline;cursor: pointer; cursor: hand; width:auto;'><b>[Opções de Script]</b></div>")
- $(".navbar").after("<div class='optionsmenu' style='display:none;background:rgb(199, 199, 199);font-weight:bold;padding:3px;cursor: pointer; cursor: hand;'></div>")
-
- $('.optionsmenu').append(' <span class="capture hov">[Capturar Pagina]</span> <span class="Dcatalog hov">[Catalogo]</span> <span class="merger hov">[Unir Imagens]</span>');
-
- $(document).on('mouseenter', ".hov", function() {
- $(this).css('background', 'orange');
- }).on('mouseleave', ".hov", function() {
- $(this).css('background', 'rgb(199, 199, 199)');
- });
-
- $(document).on('click', ".optionslink", function() {
- $(".optionsmenu").css("display","block");
- $('.optionslink').html("<b><font color='red'>[Fechar]</font></b>");
- $('.optionslink').attr('class', 'optionslinkclose hov');
-
- });
- $(document).on('click', ".optionslinkclose", function() {
- $(".optionsmenu").css("display","none");
- $('.optionslinkclose').html("<b>[Opções de Script]</b>");
- $('.optionslinkclose').attr('class', 'optionslink hov');
- });
-
-
- $(document).on('click', ".menubut", function() {
- $('.menu').attr('display', 'block');
- });
-
- //Image Merger
- $(document).on('click', ".merger", function() {
- $('body').prepend('<br><div style="display:inline-block;border:1px solid;width:auto;height:auto;" class="workspace"><center></div>');
- $('.workspace').before('<input class="maintCostField" type="file"/> Width:<input class="width" type="text"/> Height:<input class="height" type="text"/> <button class="savemerge" type="button">Salvar</button>');
- });
-
- $(document).on('click', ".savemerge", function() {
- target = $('.workarea')
- html2canvas(target, {
- onrendered: function(canvas) {
- Canvas2Image.saveAsJPEG(canvas)
- }
- });
- });
-
- $(document).on('change', '.maintCostField', function(){
- if (window.FileReader) {
- var Reader = new FileReader();
- var file = this.files[0];
- var previewarea = $('.workspace');
-
- Reader.onload = function (event) {
- previewarea.append(['<img class="dra" style="max-width:100%;max-height:100%;" src="' + event.target.result + '" alt="">'].join(''));
- }
- Reader.readAsDataURL(file);
- }
- });
-
- $(document).on('click', '.dra', function(){
- $(this).draggable();
- });
-
-
-
- $(document).on('change', '.width', function(){
- wid = $(this).val() + "px";
- $('.workspace').css('width', wid);
- });
-
- $(document).on('change', '.height', function(){
- wid = $(this).val() + "px";
- $('.workspace').css('height', wid);
- });
- //Debug
-
- $(document).on('click', ".capture", function() {
-
- html2canvas(document.body, {
- onrendered: function(canvas) {
- Canvas2Image.saveAsJPEG(canvas)
- }
- });
-
- });
-
-
- // Catalog
-
- $("<style>").text(".catalogimg > img {max-width:100%;max-height:100%;} .catalogitem {margin-bottom:10px;}").appendTo("head");
-
- $(document).on('click', ".Dcatalog", function() {
- $('.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:10px;"><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;">[Fechar Catalogo]</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);
-
-
- } 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);
- });
-
- });
-
- });
-
- $(document).on('click', ".closecat", function() {
- $('.catalog').remove();
- });
-
- //Relative Time
- function reltime() {
- $('.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 class="time">( <bold>' + tiemago + ' </bold>)</span>' );
- });
-
- };
-
- //Name Box Fixes
-
- $('input[name="name"]').get(0).type = 'password';
-
-
- $( 'input[name="name"]' ).focus(function() {
- $('input[name="name"]').get(0).type = 'text';
- $('#qr_name').get(0).type = 'text';
- });
-
- $( 'input[name="name"]' ).focusout(function() {
- $('input[name="name"]').get(0).type = 'password';
- $('#qr_name').get(0).type = 'password';
- });
-
-
- $( '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', '');};
- });
-
- //Youtube Titles
- function yttitle(me){
- var myregexp = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i;
- var src = $(me).attr("href");
- $(me).append(" - Loading Title...");
- var id = src.match(myregexp)[1];
- var link = me;
- $.ajax({
- url: "https://gdata.youtube.com/feeds/api/videos/" + id + "?v=2&alt=jsonc",
-
- dataType: "json",
- success: function(data) {
- parseresults(link,data)
- }
- });
-
- function parseresults(link,result) {
- var linktitle = result.data.title;
- $(link).text(linktitle); //setting title from extracted id
- $(link).attr('target', '_blank');
- $(link).addClass( "titled" );
- };
- };
-
- //Backlinks
-
- function backlinks() {
- $('#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('>>','');
- console.log(datas + "|" + rid + "+" + quoteds + ")");
- backquote(quoteds, rid, datas);
- });
- };
-
- function backquote(quoteds, rid, datas){
- splicer = datas.replace('.html#i','/');
- splicer2 = splicer.split('/');
- $(".reflink:contains('" +quoteds+ "')").after('<a href="/'+splicer2[1]+'/res/'+splicer2[3]+'.html#'+rid+'" onclick="return highlight(\''+rid+'\', true);" class="ref|'+splicer2[1]+'|'+splicer2[3]+'|'+rid+'">>>'+rid+'</a>');
-
- };
-
-
- /*function backlinks() {
- $('#delform').find(".reply").not('.protect').each(function() {
- $(this).addClass('protect');
- rid = this.id.replace('reply','');
- datas = $(this).find('.reflink').find("a:nth-child(2)").attr('href');
- $(this).find("a[class^='ref|']").each(function() {
- var quoted = $(this).text();
- quoteds = quoted.replace('>>','');
- console.log(datas + "|" + rid + "+" + quoteds + ")");
- backquote(quoteds, rid, datas);
- });
-
- });
- };
-
- function backquote(quoteds, rid, datas){
- splicer = datas.replace('.html#i','/');
- splicer2 = splicer.split('/');
- $(".reflink:contains('" +quoteds+ "')").after('<a href="/'+splicer2[1]+'/res/'+splicer2[3]+'.html#'+rid+'" onclick="return highlight(\''+rid+'\', true);" class="ref|'+splicer2[1]+'|'+splicer2[3]+'|'+rid+'">>>'+rid+'</a>');
-
- };*/
-
- //live index
- var highest = -Infinity;
- var compareme = 99999999999999999;
- window.updateid = "";
-
- function initupdate(){
- var highest = -Infinity;
- $('#delform').find(".reply").each(function() {
- splice = this.id.split("y");
- numb = parseInt(splice[1])
- highest = Math.max(highest, parseFloat(numb));
- });
- return highest;
- };
-
- initupdate();
-
- function update(){
- var compareme = 0;
- $.get("" + document.location, function (data) {
- $(data).find(".reply").each(function() {
- splice = this.id.split("y");
- numb = parseInt(splice[1])
- compareme = Math.max(compareme, parseFloat(numb));
- window.updateid = compareme;
- });
- });
- };
-
-
-
- setInterval(function () {
- update();
- if (window.updateid > initupdate()){
- $.get("" + document.location, function (data) {
- $("#delform").replaceWith($(data).filter("#delform"));
- }).done(function() {
- loop();
- notify();
- });
- };
- reltime();
- }, 10000);
-
-
- //Loop
- function loop(){
- $('blockquote').find('a[href*="youtube.com/watch?"]').not( ".titled" ).each(function() {
- yttitle(this);
- });
- $('blockquote').find('a').not( 'a[class^="ref|"]' ).each(function() {
- $(this).attr('target','_blank');
- });
-
- reltime();
- backlinks();
- prepqrp();
- };
-
- //Notification
-
- function notify(){
- var state = document["visibilityState"];
- if (state == "hidden")
- {
-
- $('#favicon').remove();
- $('link[rel="shortcut icon"]').remove();
- $('head').append('<link href="https://i.imgur.com/TirPmur.png" id="favicon" rel="shortcut icon">');
- } else if (state == "visible") {
- $('#favicon').remove();
- $('link[rel="shortcut icon"]').remove();
- $('head').append('<link href="https://i.imgur.com/TirPmur.png" id="favicon" rel="shortcut icon">');
- setTimeout(function(){
- $('#favicon').remove();
- $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
- },5000)
- }
- };
-
- var onVisibilityChange = function (args) {
- var state = document["visibilityState"];
- if (state == "visible")
- {
- $('#favicon').remove();
- $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
- }
- };
-
-
- document.addEventListener("visibilitychange", onVisibilityChange, false);