Advertisement
Guest User

Blockland.US Servers Apply Player Count

a guest
Aug 24th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Version 3
  2. (async function applyPlayerCount() {
  3.   if (document.documentURI == "https://blockland.us/browse.php") {
  4.     const playerCountBoxElementID = "playerCountBox";
  5.     const currentPlayerCount = await Array.from(document.getElementsByClassName("thumbBox")).map((tile) => Array.from(tile.children)).flat(1).filter((prop) => prop instanceof HTMLDivElement).map((divEle) => Array.from(divEle.children)).map((divChildren) => divChildren.filter((divChild) => divChild.innerHTML.match(/\d{1,2} \/ \d{1,2} Players/g))).flat(1).map((eachEle) => eachEle.innerHTML).map((playercountString) => parseInt(playercountString.match(/\d{1,2} \//g)[0].replace(" /", ""))).reduce((a, b) => a + b);
  6.     /** @type {HTMLDivElement|undefined|null} */
  7.     var countBox = document.getElementById(playerCountBoxElementID) ?? (() => {
  8.       const newBox = document.createElement("div");
  9.       newBox.setAttribute("id", playerCountBoxElementID);
  10.       newBox.setAttribute("style", "justify-content: center; align-items: center; padding: 10px; background-color: #c0c0c0; height: 60px; letter-spacing: 1px;");
  11.    
  12.       const elementToPrepend = document.getElementsByClassName("thumbBox").item(0).parentElement.parentElement.parentElement.parentElement;
  13.       elementToPrepend.prepend(newBox);
  14.  
  15.       return document.getElementById(playerCountBoxElementID);
  16.     })();
  17.  
  18.     if (countBox) {
  19.       countBox.innerHTML = `<b>${currentPlayerCount} Players Online</b>`;
  20.     };
  21.   };
  22. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement