Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Version 3
- (async function applyPlayerCount() {
- if (document.documentURI == "https://blockland.us/browse.php") {
- const playerCountBoxElementID = "playerCountBox";
- 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);
- /** @type {HTMLDivElement|undefined|null} */
- var countBox = document.getElementById(playerCountBoxElementID) ?? (() => {
- const newBox = document.createElement("div");
- newBox.setAttribute("id", playerCountBoxElementID);
- newBox.setAttribute("style", "justify-content: center; align-items: center; padding: 10px; background-color: #c0c0c0; height: 60px; letter-spacing: 1px;");
- const elementToPrepend = document.getElementsByClassName("thumbBox").item(0).parentElement.parentElement.parentElement.parentElement;
- elementToPrepend.prepend(newBox);
- return document.getElementById(playerCountBoxElementID);
- })();
- if (countBox) {
- countBox.innerHTML = `<b>${currentPlayerCount} Players Online</b>`;
- };
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement