Advertisement
Zacharee1

js

Jun 19th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. count = 0;
  2.                
  3.                 function ajax_get(id) {
  4.                     $.ajax({
  5.                         type: "POST",
  6.                         url: "php/bungeelog.php",
  7.                         data: id + "=",
  8.                         success: function(data) {
  9.                             var replaced = data.replace(/\\n/g, '<br />').replace(/['"]+/g, '').replace(/§r|§e|§a|\\u001b/g, '').replace(/\\\/help\\/g, "\/help");
  10.                             return replaced;
  11.                         }
  12.                     });
  13.                 }
  14.  
  15.                 function get_content(box, checkbox, ajax_get) {
  16.  
  17.  
  18.                   count++;
  19.                   //Make ajax call. and on return(complete); run it like this:
  20.                   ajax_return(box, checkbox, ajax_get);
  21.                 }
  22.  
  23.                 function add_to_box(id) {
  24.                   if (typeof id == "undefined") {
  25.                     return;
  26.                   }
  27.                   var box = $('#' + id);
  28.                   var checkbox = $('#autoscroll' + id);
  29.                   var ajax_get = ajax_get(id);
  30.  
  31.                   if (box.length < 1) {
  32.                     console.log('No box found');
  33.                     return //we did not find a valid box.
  34.                   }
  35.                   //Here we do all our checks and get our content.
  36.                   content = get_content(box, checkbox, ajax_get);
  37.                 }
  38.  
  39.                 function ajax_return(box, checkbox, content) {
  40.                   if (content == "") return;
  41.                   current_content = box.html();
  42.                   if (current_content.indexOf(content) > 0) return; //Don't do anything if the content has changed.
  43.  
  44.                   box.append(content);
  45.  
  46.                   if (checkbox.length < 1) return;
  47.                   //Now, we check that our checkbox is checked, if it is, we auto scroll to the bottom
  48.                   if (checkbox.prop('checked')) {
  49.                     box.scrollTop(box.prop("scrollHeight")); //Scroll to the bottom.
  50.                   }
  51.  
  52.                 }
  53.                 setInterval(function() {
  54.                   add_to_box('logb');
  55.                   add_to_box('logm');
  56.                 }, 500); //Adds a new line every second to both boxes.
  57.                
  58.                 $('input[type=checkbox]').change(function(){
  59.                   if($(this).prop('checked')){
  60.                     boxid=this.id.replace('autoscroll','');
  61.                     box=$('#' + boxid);
  62.                     box.scrollTop(box.prop("scrollHeight")); //Scroll to the bottom.
  63.                   }
  64.                 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement