Xchan Gold Alpha

Experimental script to enhance xchan.pw

Tính đến 01-01-2015. Xem phiên bản mới nhất.

  1. // ==UserScript==
  2. // @name Xchan Gold Alpha
  3. // @version 0.0.0.2
  4. // @description Experimental script to enhance xchan.pw
  5. // @include https://xchan.pw/*
  6. // @include http://xchan.pw/*
  7. // @require https://cdn.jsdelivr.net/jquery.timeago/1.4.1/jquery.timeago.js
  8. // @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js
  9. // @namespace https://greasyfork.org/users/2657
  10. // ==/UserScript==
  11.  
  12. //Hijacks
  13.  
  14. //Hijacks//Location hack
  15. function expandthread(){};
  16. function addpreviewevents(){};
  17. hijack = expandthread;
  18. hijack2 = addpreviewevents;
  19.  
  20. location.replace("javascript:"+ hijack +"");
  21.  
  22.  
  23. //Hijacks//Quick Reply Preview Image
  24.  
  25. $("[name='imagefile']:eq(1)").change(function () {
  26. if (window.FileReader) {
  27. var Reader = new FileReader();
  28. var file = this.files[0];
  29. window.file2 = file;
  30. var previewarea = $('.qrpreviewer');
  31. if (file.type.indexOf("video") > -1) {
  32. previewarea.html('');
  33. Reader.onload = function (event) {
  34. 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(''));
  35. }
  36. Reader.readAsDataURL(file);
  37. } else {
  38. previewarea.html('');
  39. Reader.onload = function (event) {
  40. previewarea.show().append(['<img style="max-height:88px;max-width:100px;" src="' + event.target.result + '" alt="">'].join(''));
  41. }
  42. Reader.readAsDataURL(file);
  43. };
  44. }
  45. });
  46.  
  47. //Hijacks//Quick Reply Replacer
  48. $('#qr_form').draggable();
  49.  
  50. $(document).mousemove(function (e) {
  51. window.pageX = e.pageX;
  52. window.pageY = e.pageY;
  53. });
  54.  
  55. $(document).on('click', ".qrp", function() {
  56. tidrpt = $(this).attr('title');
  57. tidrpts = tidrpt.split(' ');
  58. var threadid = tidrpts[0];
  59. var replyto = tidrpts[1];
  60. var meval = "";
  61. $('#qr_info').html("Reposta ao post: " + replyto + " na thread: " + threadid);
  62. $('#qr_name').val($.cookie("name"));
  63. $('#qr_postpassword').val($.cookie("postpassword"));
  64. $('#qr_threadid').val(threadid);
  65. meval += $('#qr_message').val();
  66. $('#qr_message').val(meval + ">>" + replyto + "\n");
  67. $('#qr_form').css({
  68. 'left' : window.pageX,
  69. 'top' : window.pageY,
  70. 'display' : 'block'
  71. }).fadeIn('slow');
  72. $('#qr_name').get(0).type = 'password';
  73. $( '.namecheck' ).appendTo( '.qr_new' );
  74. $('.postblock:contains("Mensagem"):eq(1)').append($('.movepreview'));
  75. });
  76. $(document).on('click', "img[alt='Close']", function() {
  77. $( '.namecheck' ).appendTo( '.new' );
  78. });
  79.  
  80. function prepqrp(){
  81. $('a[title="Resposta Rápida"]').each(function() {
  82. var onc = $(this).attr('onclick');
  83. oncf = onc.replace('javascript:qr(','').replace(',', '').replace(');', '');
  84. //oncfs = oncf.split(' ');
  85. $(this).attr('onclick', '');
  86. $(this).attr('title', oncf);
  87. $(this).attr('class', 'qrp');
  88. });
  89. };
  90.  
  91. //Hijacks//Expand Thread
  92. $(document).on('click', ".expandthread", function() {
  93. var tid = $(this).parent().attr('onclick');
  94. tids = tid.split("'");
  95. var c = tids[1];
  96. var d = tids[3];
  97. var e = $("#replies" + c + d);
  98. if (e.length) {
  99. e.prepend(_('Expanding thread') + '...<br /><br />');
  100. e.load(ku_boardspath + '/expand.php?board=' + d + '&threadid=' + c, {}, function (a, b) {
  101. if (!a) {
  102. e.html(_("something went wrong (blank response)"))
  103. }
  104. if (b == "error") {
  105. alert(_('Something went wrong...'))
  106. }
  107. delandbanlinks(this);
  108. loop();
  109. })
  110. }
  111. return false
  112. });
  113.  
  114.  
  115. //Hijacks//Hover
  116.  
  117. $("<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");
  118.  
  119. $('.logo').append('<div class="previews"></div>');
  120.  
  121. $(document).on('mouseenter', 'a[class^="ref|"]', function() {
  122. $('.floater').attr('class', 'hold');
  123. var c = $(this).attr("class").split('|');
  124. var d = $("<div></div>").addClass('floater').attr({
  125. style : "position:absolute;width:400px;"
  126. });
  127. 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)) {
  128. var f = true;
  129. d.html($("#reply" + c[3]).parents("table").html())
  130. } else {
  131. d.html('Carregando...').toggle("normal");
  132. $.get(ku_boardspath + '/read.php?b=' + c[1] + '&t=' + c[2] + '&p=' + c[3] + '&single', {}, function (a, b) {
  133. if (b != "success") {
  134. alert('wut')
  135. } else {
  136. if (a) {
  137. d.html(a)
  138. } else {
  139. d.html(_("something went wrong (blank response)"))
  140. }
  141. }
  142. })
  143. }
  144. $('.previews').append(d).slideDown( "slow" );
  145. //loop();
  146. if (f) {
  147. //d.toggle("normal")
  148. };
  149. $('.floater')
  150. .css("top",$(this).offset().top)
  151. .css("left",($(this).offset().left-100))
  152. });
  153.  
  154. $(document).on('mouseleave', '.previews', function() {
  155. $('.floater').remove();
  156. $('.hold').remove();
  157. });
  158.  
  159.  
  160. //Start
  161. $( document ).ready(function() {
  162. loop();
  163. $('#favicon').remove();
  164. $('link[rel="shortcut icon"]').remove();
  165. $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
  166. //addpreviewevents2();
  167. $('#qr_form').find('.postblock:contains("Mensagem")').append('<div class="qrpreviewer"></div>');
  168. $('.qrpreviewer').attr('style', 'background:none; border:0px; width:100px; padding:0px; position:relative; ');
  169. });
  170.  
  171. window.dt = "";
  172.  
  173.  
  174. //Menu
  175.  
  176. $(".navbar").after("<div class='optionslink hov' style='display:inline;cursor: pointer; cursor: hand; width:auto;'><b>[Opções de Script]</b></div>")
  177. $(".navbar").after("<div class='optionsmenu' style='display:none;background:rgb(199, 199, 199);font-weight:bold;padding:3px;cursor: pointer; cursor: hand;'></div>")
  178.  
  179. $('.optionsmenu').append(' <span class="capture hov">[Capturar Pagina]</span> <span class="Dcatalog hov">[Catalogo]</span> <span class="merger hov">[Unir Imagens]</span>');
  180.  
  181. $(document).on('mouseenter', ".hov", function() {
  182. $(this).css('background', 'orange');
  183. }).on('mouseleave', ".hov", function() {
  184. $(this).css('background', 'rgb(199, 199, 199)');
  185. });
  186.  
  187. $(document).on('click', ".optionslink", function() {
  188. $(".optionsmenu").css("display","block");
  189. $('.optionslink').html("<b><font color='red'>[Fechar]</font></b>");
  190. $('.optionslink').attr('class', 'optionslinkclose hov');
  191. });
  192. $(document).on('click', ".optionslinkclose", function() {
  193. $(".optionsmenu").css("display","none");
  194. $('.optionslinkclose').html("<b>[Opções de Script]</b>");
  195. $('.optionslinkclose').attr('class', 'optionslink hov');
  196. });
  197.  
  198.  
  199. $(document).on('click', ".menubut", function() {
  200. $('.menu').attr('display', 'block');
  201. });
  202.  
  203. //Image Merger
  204. $(document).on('click', ".merger", function() {
  205. $('body').prepend('<br><div style="display:inline-block;border:1px solid;width:auto;height:auto;" class="workspace"><center></div>');
  206. $('.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>');
  207. });
  208.  
  209. $(document).on('click', ".savemerge", function() {
  210. target = $('.workarea')
  211. html2canvas(target, {
  212. onrendered: function(canvas) {
  213. Canvas2Image.saveAsJPEG(canvas)
  214. }
  215. });
  216. });
  217.  
  218. $(document).on('change', '.maintCostField', function(){
  219. if (window.FileReader) {
  220. var Reader = new FileReader();
  221. var file = this.files[0];
  222. var previewarea = $('.workspace');
  223. Reader.onload = function (event) {
  224. previewarea.append(['<img class="dra" style="max-width:100%;max-height:100%;" src="' + event.target.result + '" alt="">'].join(''));
  225. }
  226. Reader.readAsDataURL(file);
  227. }
  228. });
  229.  
  230. $(document).on('click', '.dra', function(){
  231. $(this).draggable();
  232. });
  233.  
  234.  
  235.  
  236. $(document).on('change', '.width', function(){
  237. wid = $(this).val() + "px";
  238. $('.workspace').css('width', wid);
  239. });
  240.  
  241. $(document).on('change', '.height', function(){
  242. wid = $(this).val() + "px";
  243. $('.workspace').css('height', wid);
  244. });
  245. //Debug
  246.  
  247. $(document).on('click', ".capture", function() {
  248. html2canvas(document.body, {
  249. onrendered: function(canvas) {
  250. Canvas2Image.saveAsJPEG(canvas)
  251. }
  252. });
  253. });
  254.  
  255.  
  256. // Catalog
  257.  
  258. $("<style>").text(".catalogimg > img {max-width:100%;max-height:100%;} .catalogitem {margin-bottom:10px;}").appendTo("head");
  259.  
  260. $(document).on('click', ".Dcatalog", function() {
  261. $('.catalog').remove();
  262. $('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>');
  263. $.get("https://xchan.pw/b/catalog.html", function (data) {
  264. $(data).find('a[class^="ref|"]').each(function () {
  265. var href = $(this).attr('href');
  266. var c = $(this).attr("class").split('|');
  267. var d = $("<span></span>").addClass('catalogimg').attr({
  268. style : "max-width:220px;background:#F7F7F7;"
  269. });
  270. var g = $("<div></div>").addClass('catalogtext').attr({
  271. style : "overflow-x:hidden;overflow-y:scroll;max-height:200px;max-width:220px;background:#F7F7F7;"
  272. });
  273. $.get(ku_boardspath + '/read.php?b=' + c[1] + '&t=' + c[2] + '&p=' + c[3] + '&single', {}, function (a, b) {
  274. if (b != "success") {
  275. alert('wut')
  276. } else {
  277. if (a) {
  278. var z = $('<img />').html(a).find('.thumb').removeClass();
  279. var y = $('<blockquote>').html(a).find('blockquote');
  280.  
  281. d.html(z);
  282. g.html(y);
  283. } else {
  284. d.html(_("something went wrong (blank response)"))
  285. }
  286. }
  287. })
  288. var wrap = $("<div></div>").addClass('catalogitem').append(d).wrapInner('<a href='+ href +'>').append(g);
  289. $('#catalogt').append(wrap);
  290. });
  291.  
  292. });
  293. });
  294.  
  295. $(document).on('click', ".closecat", function() {
  296. $('.catalog').remove();
  297. });
  298.  
  299. //Relative Time
  300. function reltime() {
  301. $('.time').remove();
  302. $( "label:contains('@')" ).each(function() {
  303. var vovar = $(this).contents().map(function() {
  304. if( this.nodeType === 3 ) {
  305. return this.data;
  306. }
  307. }).get().join('');
  308. vovar1 = vovar.split("@");
  309. vovardate = vovar1[0].split("/");
  310. vovaryear = vovardate[2].split(" ");
  311. vovarmonth = vovardate[1] - 1;
  312. vovartime = vovar1[1].split(":");
  313. tiem = new Date(vovaryear[0], vovarmonth, vovardate[0], vovartime[0], vovartime[1])
  314. tiemiso = tiem.toISOString();
  315. tiemago = jQuery.timeago(tiemiso);
  316. $( this ).append( '<span class="time">( <bold>' + tiemago + ' </bold>)</span>' );
  317. });
  318. };
  319.  
  320. //Name Box Fixes
  321.  
  322. $('input[name="name"]').get(0).type = 'password';
  323.  
  324.  
  325. $( 'input[name="name"]' ).focus(function() {
  326. $('input[name="name"]').get(0).type = 'text';
  327. $('#qr_name').get(0).type = 'text';
  328. });
  329.  
  330. $( 'input[name="name"]' ).focusout(function() {
  331. $('input[name="name"]').get(0).type = 'password';
  332. $('#qr_name').get(0).type = 'password';
  333. });
  334.  
  335.  
  336. $( 'input[name="name"]:first' ).wrap( '<span class="new"></span>' );
  337. $( '#qr_name' ).wrap( '<span class="qr_new"></span>' );
  338. $( '.new' ).append( '<input type="checkbox" class="namecheck" value="Bike" checked="checked">' );
  339. if (localStorage.getItem("namecheck") === null) {}else{$( ".namecheck" ).prop( "checked", false ); $( 'input[name="name"], #qr_name' ).prop('disabled',true);};
  340.  
  341. $(document).on('change', ".namecheck", function() {
  342. 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', '');};
  343. });
  344.  
  345. //Youtube Titles
  346. function yttitle(me){
  347. var myregexp = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i;
  348. var src = $(me).attr("href");
  349. $(me).append(" - Loading Title...");
  350. var id = src.match(myregexp)[1];
  351. var link = me;
  352. $.ajax({
  353. url: "https://gdata.youtube.com/feeds/api/videos/" + id + "?v=2&alt=jsonc",
  354. dataType: "json",
  355. success: function(data) {
  356. parseresults(link,data)
  357. }
  358. });
  359. function parseresults(link,result) {
  360. var linktitle = result.data.title;
  361. $(link).text(linktitle); //setting title from extracted id
  362. $(link).attr('target', '_blank');
  363. $(link).addClass( "titled" );
  364. };
  365. };
  366.  
  367. //Backlinks
  368.  
  369. function backlinks() {
  370. $('#delform').find(".reply").not('.protect').each(function() {
  371. blink($(this));
  372. });
  373. $('.floater, .hold').find(".reply").not('.protect').each(function() {
  374. blink($(this));
  375. });
  376. };
  377.  
  378. function blink(t){
  379. t.addClass('protect');
  380. rid = t.attr('id').replace('reply','');
  381. datas = t.find('.reflink').find("a:nth-child(2)").attr('href');
  382. t.find("a[class^='ref|']").each(function() {
  383. var quoted = $(this).text();
  384. quoteds = quoted.replace('>>','');
  385. console.log(datas + "|" + rid + "+" + quoteds + ")");
  386. backquote(quoteds, rid, datas);
  387. });
  388. };
  389.  
  390. function backquote(quoteds, rid, datas){
  391. splicer = datas.replace('.html#i','/');
  392. splicer2 = splicer.split('/');
  393. $(".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+'">&gt;&gt;'+rid+'</a>');
  394. };
  395.  
  396.  
  397. /*function backlinks() {
  398. $('#delform').find(".reply").not('.protect').each(function() {
  399. $(this).addClass('protect');
  400. rid = this.id.replace('reply','');
  401. datas = $(this).find('.reflink').find("a:nth-child(2)").attr('href');
  402. $(this).find("a[class^='ref|']").each(function() {
  403. var quoted = $(this).text();
  404. quoteds = quoted.replace('>>','');
  405. console.log(datas + "|" + rid + "+" + quoteds + ")");
  406. backquote(quoteds, rid, datas);
  407. });
  408. });
  409. };
  410.  
  411. function backquote(quoteds, rid, datas){
  412. splicer = datas.replace('.html#i','/');
  413. splicer2 = splicer.split('/');
  414. $(".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+'">&gt;&gt;'+rid+'</a>');
  415. };*/
  416.  
  417. //live index
  418. var highest = -Infinity;
  419. var compareme = 99999999999999999;
  420. window.updateid = "";
  421.  
  422. function initupdate(){
  423. var highest = -Infinity;
  424. $('#delform').find(".reply").each(function() {
  425. splice = this.id.split("y");
  426. numb = parseInt(splice[1])
  427. highest = Math.max(highest, parseFloat(numb));
  428. });
  429. return highest;
  430. };
  431.  
  432. initupdate();
  433.  
  434. function update(){
  435. var compareme = 0;
  436. $.get("" + document.location, function (data) {
  437. $(data).find(".reply").each(function() {
  438. splice = this.id.split("y");
  439. numb = parseInt(splice[1])
  440. compareme = Math.max(compareme, parseFloat(numb));
  441. window.updateid = compareme;
  442. });
  443. });
  444. };
  445.  
  446.  
  447.  
  448. setInterval(function () {
  449. update();
  450. if (window.updateid > initupdate()){
  451. $.get("" + document.location, function (data) {
  452. $("#delform").replaceWith($(data).filter("#delform"));
  453. }).done(function() {
  454. loop();
  455. notify();
  456. });
  457. };
  458. reltime();
  459. }, 10000);
  460.  
  461.  
  462. //Loop
  463. function loop(){
  464. $('blockquote').find('a[href*="youtube.com/watch?"]').not( ".titled" ).each(function() {
  465. yttitle(this);
  466. });
  467. $('blockquote').find('a').not( 'a[class^="ref|"]' ).each(function() {
  468. $(this).attr('target','_blank');
  469. });
  470. reltime();
  471. backlinks();
  472. prepqrp();
  473. };
  474.  
  475. //Notification
  476.  
  477. function notify(){
  478. var state = document["visibilityState"];
  479. if (state == "hidden")
  480. {
  481. $('#favicon').remove();
  482. $('link[rel="shortcut icon"]').remove();
  483. $('head').append('<link href="https://i.imgur.com/TirPmur.png" id="favicon" rel="shortcut icon">');
  484. } else if (state == "visible") {
  485. $('#favicon').remove();
  486. $('link[rel="shortcut icon"]').remove();
  487. $('head').append('<link href="https://i.imgur.com/TirPmur.png" id="favicon" rel="shortcut icon">');
  488. setTimeout(function(){
  489. $('#favicon').remove();
  490. $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
  491. },5000)
  492. }
  493. };
  494.  
  495. var onVisibilityChange = function (args) {
  496. var state = document["visibilityState"];
  497. if (state == "visible")
  498. {
  499. $('#favicon').remove();
  500. $('head').append('<link href="https://i.imgur.com/AB4G76Z.png" id="favicon" rel="shortcut icon">');
  501. }
  502. };
  503.  
  504.  
  505. document.addEventListener("visibilitychange", onVisibilityChange, false);