Advertisement
MeKLiN2

Untitled

Mar 22nd, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. /*jshint esversion: 6 */
  2. (function () {
  3. 'use strict';
  4. // DELETE SOON
  5.  
  6. function getRandomNumber(min, max) {
  7. return Math.random() * (max - min) + min;
  8. }
  9. function randomizePosition() {
  10. const topPercentage = getRandomNumber(1, 99); // Random percentage for top position
  11. const leftPercentage = getRandomNumber(1, 99); // Random percentage for left position
  12.  
  13. return {
  14. top: topPercentage + '%',
  15. left: leftPercentage + '%'
  16. };
  17. }
  18.  
  19.  
  20. function createHeart() {
  21. const emoticons = ['🍻', '🍀'];
  22. const randomEmoticon = emoticons[Math.floor(Math.random() * emoticons.length)];
  23.  
  24. const heart = document.createElement('div');
  25. heart.classList.add('heart');
  26. heart.innerHTML = randomEmoticon; // Set inner HTML to the randomly selected emoticon
  27.  
  28. const position = randomizePosition();
  29. heart.style.top = position.top;
  30. heart.style.left = position.left;
  31.  
  32. if (Math.random() < 0.7) {
  33. heart.style.fontSize = getRandomNumber(20, 50) + 'px'; // Large heart
  34. } else {
  35. heart.style.fontSize = getRandomNumber(10, 20) + 'px'; // Small heart
  36. }
  37.  
  38. document.querySelector(".wrapper.publicrooms").appendChild(heart);
  39. }
  40.  
  41.  
  42.  
  43. // DELETE SOON
  44. window.addEventListener(`DOMContentLoaded`, () => {
  45.  
  46. loadPage(1);
  47. let content = document.querySelector(`.content`);
  48. document.addEventListener("pointerup", (e) => {
  49. if (e.target.id == "scrollup") {
  50. content.scrollTop = 0;
  51. } else if (e.target.classList.contains("prev") || e.target.classList.contains("next")) {
  52. let elements = e.target.parentElement.querySelectorAll('.slides');
  53. for (const element in elements) {
  54. if (elements[ element ].style.display === "block") {
  55. elements[ element ].style.removeProperty("display");
  56. 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";
  57. break;
  58. }
  59. }
  60. } else if (e.target.getAttribute("page-id") != undefined && !e.target.classList.contains("active")) {
  61. loadPage(e.target.getAttribute("page-id"));
  62. }
  63. }, { passive: true });
  64.  
  65. content.addEventListener(`scroll`, () => document.getElementById(`scrollup`).style.display = (content.scrollTop > 20) ? `block` : `none`, { passive: true });
  66. }, { passive: true, once: true });
  67.  
  68. function loadPage (page) {
  69. document.querySelector(".publicrooms").innerHTML = "";
  70. let Token = new XMLHttpRequest();
  71. Token.open("POST", `https://${window.location.hostname}/lbstats`);
  72. Token.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  73. Token.setRequestHeader("CSRF-Token", document.getElementsByName('_csrf')[ 0 ].getAttribute("content"));
  74. Token.onload = () => {
  75. if (Token.status != 200) {
  76. 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>`;
  77. return;
  78. }
  79. let parse;
  80. try {
  81. parse = JSON.parse(Token.responseText);
  82. } catch (err) {
  83. document.querySelector(".publicrooms").innerHTML = `<h1>PUBLIC ROOM SEARCH LOCKED TEMPORARILY</h1>`;
  84. return;
  85. }
  86. if (parse.error != undefined && parse.error == 0) {
  87. document.querySelector(".publicrooms").innerHTML = `<h1>YOU'VE EXCEEDED RATELIMITS</h1>`;
  88. return;
  89. }
  90. if (parse.error != undefined && parse.error == 22) {
  91. document.querySelector(".publicrooms").innerHTML = `<h1>Something went wrong, refresh.</h1>`;
  92. return;
  93. }
  94. if (parse.rooms.length == 0) {
  95. 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>`;
  96. return;
  97. }
  98. document.querySelector(".publicrooms").innerHTML = `<div class="centered bubble"></div>`;
  99.  
  100. let time = 0;
  101. for (let i = 0; i < parse.rooms.length; i++) {
  102. if (i % 5 == 0) time += 200;
  103. SpawnRoom(time, parse.rooms[ i ]);
  104. }
  105.  
  106. document.querySelector(".publicrooms").innerHTML += `<div class="pagination-wrapper"><div class="pagination"></div></div>`;
  107. let paginationElem = document.querySelector(".pagination");
  108.  
  109. let start = (parse.currentPage == 1) ? 1 : (parse.currentPage - 2 < 1) ? 1 : parse.currentPage - 2;
  110. let end = (parse.currentPage == parse.totalPages) ? parse.totalPages : ((parse.currentPage + 2) > parse.totalPages) ? (parse.totalPages - ((parse.currentPage + 2) - parse.totalPages)) + 1 : (parse.currentPage + 2);
  111.  
  112. if (parse.currentPage != 1) paginationElem.innerHTML = `<div page-id="${parse.currentPage - 1}">&laquo;</div>`;
  113.  
  114. if (start != end) for (let pages = start; pages <= end; pages++) paginationElem.innerHTML += `<div page-id="${pages}"${(parse.currentPage == pages) ? `class="active"` : ``}>${pages}</div>`;
  115. if (end < parse.totalPages) paginationElem.innerHTML += `<div page-id="${parse.totalPages}">${parse.totalPages}</div>`;
  116. if (parse.totalPages > parse.currentPage) paginationElem.innerHTML += `<div page-id="${parse.currentPage + 1}">&raquo;</div>`;
  117.  
  118. Token = null;
  119. start = null;
  120. end = null;
  121. parse = null;
  122. paginationElem = null;
  123. //delete soon
  124. //for(let ammount = 0; ammount <= 200; ammount++) setTimeout(createHeart, getRandomNumber(1000, 5000));
  125.  
  126. };
  127. Token.onerror = () => {
  128. Token = null;
  129. document.querySelector(".publicrooms").innerHTML = `<h1>Could not connect to directory listings, refresh.</h1>`;
  130. };
  131. Token.send(`page=${page}`);
  132. }
  133. function SpawnRoom (time, parsedRoom) {
  134. setTimeout((room) => {
  135. 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">&#10094;</a> <a class="next">&#10095;</a> </div> </div> <div class="description"><h4>${room.topic}</h4></div> </div> </div>`;
  136.  
  137. let users = shuffle(Object.entries(room.user));
  138. if (users.length > 0) {
  139. users.forEach((avatar, index) => document.querySelector(`a[room-name="${room.name}"]`).innerHTML += `<div class="slides fade"><img src="${avatar[ 1 ]}" alt="Room Broadcast" /></div>`);
  140. 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 });
  141. 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 });
  142. document.querySelector(`a[room-name="${room.name}"]>div.slides`).style.display = "block";
  143. } else {
  144. GenerateAvatar(`profile/${room.name.toLowerCase()}/cached/large_avatar.jpg`, (result) => {
  145. 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>`;
  146. 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 });
  147. 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 });
  148. document.querySelector(`a[room-name="${room.name}"]>div.slides`).style.display = "block";
  149. });
  150. }
  151. }, time, parsedRoom);
  152. }
  153. function shuffle (sourceArray) {
  154. for (var i = 0; i < sourceArray.length - 1; i++) {
  155. var j = i + Math.floor(Math.random() * (sourceArray.length - i));
  156. var temp = sourceArray[ j ];
  157. sourceArray[ j ] = sourceArray[ i ];
  158. sourceArray[ i ] = temp;
  159. }
  160. return sourceArray;
  161. }
  162. function GenerateAvatar (url, resolve) {
  163. fetch(`https://${window.location.hostname}/${url}`).then((response) => {
  164. if (response.status != 200) throw new Error;
  165. return response.blob();
  166. }).then((blob) => {
  167. if (blob.type != "image/jpeg") return resolve(null);
  168. let reader = new FileReader();
  169. reader.onloadend = () => resolve(reader.result);
  170. reader.onerror = () => resolve(null);
  171. reader.readAsDataURL(blob);
  172. }).catch((err) => {
  173. resolve(null);
  174. });
  175. }
  176. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement