Advertisement
Foxscotch

Extended Who's Online

Oct 28th, 2015
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Extended Who's Online
  3. // @namespace    https://foxscotch.us/
  4. // @version      1.1
  5. // @description  Script that places all pages of the BLF Who's Online list onto one page.
  6. // @author       Foxscotch
  7. // @match        https://forum.blockland.us/index.php?action=who*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11.  
  12. // Change this to true if you want it to include guests
  13. var includeGuests = false;
  14.  
  15. // Change this to true if you want it to automatically start when you load the user list
  16. var automatic = false;
  17.  
  18.  
  19. var userTable = document.getElementsByTagName('table')[2].children[0];
  20.  
  21. function emptyTable() {
  22.     var tableLength = userTable.children.length
  23.     for (var i = 1; i < tableLength - 1; i++) {
  24.         userTable.removeChild(userTable.children[1]);
  25.     }
  26. }
  27.  
  28. function correctColors() {
  29.     var tableLength = userTable.children.length
  30.     for (var k = 1; k < tableLength - 1; k++) {
  31.         if (k % 2 == 0) {
  32.             userTable.children[k].className = 'windowbg';
  33.         }
  34.         else {
  35.             userTable.children[k].className = 'windowbg2';
  36.         }
  37.     }
  38. }
  39.  
  40. function clearDuplicates() {
  41.     var duplicates = []
  42.     for (var i = 1; i < userTable.children.length - 1; i++) {
  43.         var username = userTable.children[i].getElementsByTagName('span')[0].children[0].innerHTML;
  44.         if (duplicates.indexOf(username) == -1) {
  45.             duplicates.push(username);
  46.         }
  47.         else {
  48.             userTable.removeChild(userTable.children[i]);
  49.         }
  50.     }
  51. }
  52.  
  53. function addUsers () {
  54.     var pageCount = Number(document.getElementsByClassName('navPages')[document.getElementsByClassName('navPages').length - 1].innerHTML);
  55.     var pagination = userTable.children[userTable.children.length - 1];
  56.  
  57.     var url = String(window.location);
  58.     if (url.includes('start')) {
  59.         url = url.replace(/;?start=[\d]+/, '');
  60.     }
  61.  
  62.     for (var i = 2; i <= pageCount; i++) {
  63.         var request = new XMLHttpRequest();
  64.         request.responseType = 'document';
  65.         request.onload = function () {
  66.             var newUserTable = this.response.getElementsByTagName('table')[2].children[0];
  67.             for (var j = 1; j < newUserTable.children.length - 1 ; j++) {
  68.                 var currentEntry = newUserTable.children[j];
  69.                 if (includeGuests) {
  70.                     userTable.insertBefore(currentEntry, pagination);
  71.                 }
  72.                 else if (!currentEntry.children[0].innerHTML.includes('Guest')) {
  73.                     userTable.insertBefore(currentEntry, pagination);
  74.                 }
  75.             }
  76.             correctColors();
  77.             clearDuplicates();
  78.         };
  79.         request.open('GET', url + ';start=' + ((i - 2) * 30));
  80.         request.send();
  81.     }
  82. }
  83.  
  84.  
  85. if (automatic) {
  86.     emptyTable();
  87.     addUsers();
  88. }
  89. else {
  90.     var button = document.createElement('button');
  91.     button.innerHTML = 'Add users';
  92.    
  93.     place = document.body.children[2].children[0]
  94.     button = place.insertBefore(button, place.children[0])
  95.    
  96.     button.addEventListener('click', function(){emptyTable();addUsers();});
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement