Advertisement
Czogista

alkatria > chat.js

Dec 18th, 2022
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   initializeChat() {
  2.     // initializeChat is called when the init from json.php is recived
  3.  
  4.     for (const element of document.querySelectorAll(
  5.       ".chat-messages:not(.chat-messages-2)"
  6.     )) {
  7.       // excluding server logs
  8.       element.addEventListener("mouseover", (e) => {
  9.         let { target } = e;
  10.         if (!target) return;
  11.         if (target.nodeName !== "SPAN") return;
  12.         if (!target.hasAttribute("title")) target = target.parentElement;
  13.         const playerName = target.querySelector("span").innerText;
  14.         for (const playerMessage of element.children) {
  15.           if (playerMessage.querySelector("span").innerText !== playerName) {
  16.             // highlighting only messages from the same player
  17.             continue;
  18.           }
  19.           playerMessage.classList.add("chat-message-hovered");
  20.         }
  21.       });
  22.       element.addEventListener("mouseout", (e) => {
  23.         document.querySelectorAll(".chat-message-hovered").forEach((el) => {
  24.           el.classList.remove("chat-message-hovered");
  25.         });
  26.       });
  27.     }
  28.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement