Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jshint esversion: 6 */
- (function () {
- 'use strict';
- // DELETE SOON
- function getRandomNumber(min, max) {
- return Math.random() * (max - min) + min;
- }
- function randomizePosition() {
- const topPercentage = getRandomNumber(1, 99); // Random percentage for top position
- const leftPercentage = getRandomNumber(1, 99); // Random percentage for left position
- return {
- top: topPercentage + '%',
- left: leftPercentage + '%'
- };
- }
- function createHeart() {
- const emoticons = ['🍻', '🍀'];
- const randomEmoticon = emoticons[Math.floor(Math.random() * emoticons.length)];
- const heart = document.createElement('div');
- heart.classList.add('heart');
- heart.innerHTML = randomEmoticon; // Set inner HTML to the randomly selected emoticon
- const position = randomizePosition();
- heart.style.top = position.top;
- heart.style.left = position.left;
- if (Math.random() < 0.7) {
- heart.style.fontSize = getRandomNumber(20, 50) + 'px'; // Large heart
- } else {
- heart.style.fontSize = getRandomNumber(10, 20) + 'px'; // Small heart
- }
- document.querySelector(".wrapper.publicrooms").appendChild(heart);
- }
- // DELETE SOON
- window.addEventListener(`DOMContentLoaded`, () => {
- loadPage(1);
- let content = document.querySelector(`.content`);
- document.addEventListener("pointerup", (e) => {
- if (e.target.id == "scrollup") {
- content.scrollTop = 0;
- } else if (e.target.classList.contains("prev") || e.target.classList.contains("next")) {
- let elements = e.target.parentElement.querySelectorAll('.slides');
- for (const element in elements) {
- if (elements[ element ].style.display === "block") {
- elements[ element ].style.removeProperty("display");
- elements[ (e.target.classList.contains("prev")) ? ((element == 0) ? elements.length - 1 : parseInt(element) - 1) : ((element == elements.length - 1) ? 0 : parseInt(element) + 1) ].style.display = "block";
- break;
- }
- }
- } else if (e.target.getAttribute("page-id") != undefined && !e.target.classList.contains("active")) {
- loadPage(e.target.getAttribute("page-id"));
- }
- }, { passive: true });
- content.addEventListener(`scroll`, () => document.getElementById(`scrollup`).style.display = (content.scrollTop > 20) ? `block` : `none`, { passive: true });
- }, { passive: true, once: true });
- function loadPage (page) {
- document.querySelector(".publicrooms").innerHTML = "";
- let Token = new XMLHttpRequest();
- Token.open("POST", `https://${window.location.hostname}/lbstats`);
- Token.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- Token.setRequestHeader("CSRF-Token", document.getElementsByName('_csrf')[ 0 ].getAttribute("content"));
- Token.onload = () => {
- if (Token.status != 200) {
- document.querySelector(".publicrooms").innerHTML = `<h1>THERE ARE CURRENTLY NO PUBLIC ROOMS ONLINE. HOWEVER POSSIBLE SERVER IS BEING REBOOTED RIGHT NOW WAIT A FEW MOMENTS AND TRY AGAIN.</h1>`;
- return;
- }
- let parse;
- try {
- parse = JSON.parse(Token.responseText);
- } catch (err) {
- document.querySelector(".publicrooms").innerHTML = `<h1>PUBLIC ROOM SEARCH LOCKED TEMPORARILY</h1>`;
- return;
- }
- if (parse.error != undefined && parse.error == 0) {
- document.querySelector(".publicrooms").innerHTML = `<h1>YOU'VE EXCEEDED RATELIMITS</h1>`;
- return;
- }
- if (parse.error != undefined && parse.error == 22) {
- document.querySelector(".publicrooms").innerHTML = `<h1>Something went wrong, refresh.</h1>`;
- return;
- }
- if (parse.rooms.length == 0) {
- document.querySelector(".publicrooms").innerHTML = `<h1>THERE ARE CURRENTLY NO PUBLIC ROOMS ONLINE. HOWEVER POSSIBLE SERVER IS BEING REBOOTED RIGHT NOW WAIT A FEW MOMENTS AND TRY AGAIN.</h1>`;
- return;
- }
- document.querySelector(".publicrooms").innerHTML = `<div class="centered bubble"></div>`;
- let time = 0;
- for (let i = 0; i < parse.rooms.length; i++) {
- if (i % 5 == 0) time += 200;
- SpawnRoom(time, parse.rooms[ i ]);
- }
- document.querySelector(".publicrooms").innerHTML += `<div class="pagination-wrapper"><div class="pagination"></div></div>`;
- let paginationElem = document.querySelector(".pagination");
- let start = (parse.currentPage == 1) ? 1 : (parse.currentPage - 2 < 1) ? 1 : parse.currentPage - 2;
- let end = (parse.currentPage == parse.totalPages) ? parse.totalPages : ((parse.currentPage + 2) > parse.totalPages) ? (parse.totalPages - ((parse.currentPage + 2) - parse.totalPages)) + 1 : (parse.currentPage + 2);
- if (parse.currentPage != 1) paginationElem.innerHTML = `<div page-id="${parse.currentPage - 1}">«</div>`;
- if (start != end) for (let pages = start; pages <= end; pages++) paginationElem.innerHTML += `<div page-id="${pages}"${(parse.currentPage == pages) ? `class="active"` : ``}>${pages}</div>`;
- if (end < parse.totalPages) paginationElem.innerHTML += `<div page-id="${parse.totalPages}">${parse.totalPages}</div>`;
- if (parse.totalPages > parse.currentPage) paginationElem.innerHTML += `<div page-id="${parse.currentPage + 1}">»</div>`;
- Token = null;
- start = null;
- end = null;
- parse = null;
- paginationElem = null;
- //delete soon
- //for(let ammount = 0; ammount <= 200; ammount++) setTimeout(createHeart, getRandomNumber(1000, 5000));
- };
- Token.onerror = () => {
- Token = null;
- document.querySelector(".publicrooms").innerHTML = `<h1>Could not connect to directory listings, refresh.</h1>`;
- };
- Token.send(`page=${page}`);
- }
- function SpawnRoom (time, parsedRoom) {
- setTimeout((room) => {
- document.querySelector(".publicrooms>.centered").innerHTML += `<div class="grid-item"> <div class="room-wrap"> <div class="roomname"><h3>${room.name}</h3></div> <div class="details"> <div class="detailbadge broadcast">${room.broadcasting_count}</div> <div class="detailbadge users">${room.watching_count}</div> </div> <div class="thumbnail"> <div class="slideshow" slide-show="${room.name}"> <a href="/room/${room.name}" room-name="${room.name}"></a> <a class="prev">❮</a> <a class="next">❯</a> </div> </div> <div class="description"><h4>${room.topic}</h4></div> </div> </div>`;
- let users = shuffle(Object.entries(room.user));
- if (users.length > 0) {
- users.forEach((avatar, index) => document.querySelector(`a[room-name="${room.name}"]`).innerHTML += `<div class="slides fade"><img src="${avatar[ 1 ]}" alt="Room Broadcast" /></div>`);
- if (document.querySelector(`body > div.content > div:nth-child(3) > div`)) new Masonry(`body > div.content > div:nth-child(3) > div`, { "itemSelector": `.grid-item`, "columnWidth": 250, "gutter": 15, "fitWidth": true });
- if (document.querySelector(`body > div.content > div:nth-child(5) > div`)) new Masonry(`body > div.content > div:nth-child(5) > div`, { "itemSelector": `.grid-item`, "columnWidth": 250, "gutter": 15, "fitWidth": true });
- document.querySelector(`a[room-name="${room.name}"]>div.slides`).style.display = "block";
- } else {
- GenerateAvatar(`profile/${room.name.toLowerCase()}/cached/large_avatar.jpg`, (result) => {
- document.querySelector(`a[room-name="${room.name}"]`).innerHTML = (result == null) ? `<div class="slides" style="display: block;"><div alt="No Broadcasts" class="no-avatar"></div></div>` : `<div class="slides fade" style="display: block;"><img src="${result}" alt="Room Broadcast" /></div>`;
- if (document.querySelector(`body > div.content > div:nth-child(3) > div`)) new Masonry(`body > div.content > div:nth-child(3) > div`, { "itemSelector": `.grid-item`, "columnWidth": 250, "gutter": 15, "fitWidth": true });
- if (document.querySelector(`body > div.content > div:nth-child(5) > div`)) new Masonry(`body > div.content > div:nth-child(5) > div`, { "itemSelector": `.grid-item`, "columnWidth": 250, "gutter": 15, "fitWidth": true });
- document.querySelector(`a[room-name="${room.name}"]>div.slides`).style.display = "block";
- });
- }
- }, time, parsedRoom);
- }
- function shuffle (sourceArray) {
- for (var i = 0; i < sourceArray.length - 1; i++) {
- var j = i + Math.floor(Math.random() * (sourceArray.length - i));
- var temp = sourceArray[ j ];
- sourceArray[ j ] = sourceArray[ i ];
- sourceArray[ i ] = temp;
- }
- return sourceArray;
- }
- function GenerateAvatar (url, resolve) {
- fetch(`https://${window.location.hostname}/${url}`).then((response) => {
- if (response.status != 200) throw new Error;
- return response.blob();
- }).then((blob) => {
- if (blob.type != "image/jpeg") return resolve(null);
- let reader = new FileReader();
- reader.onloadend = () => resolve(reader.result);
- reader.onerror = () => resolve(null);
- reader.readAsDataURL(blob);
- }).catch((err) => {
- resolve(null);
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement