|
@@ -80,6 +80,7 @@ const chatMessagesElement = document.getElementById("chatMessages");
|
|
|
const chatInputElement = document.getElementById("chatInput");
|
|
const chatInputElement = document.getElementById("chatInput");
|
|
|
const chatForm = document.getElementById("chatForm");
|
|
const chatForm = document.getElementById("chatForm");
|
|
|
const userList = document.getElementById("userList")
|
|
const userList = document.getElementById("userList")
|
|
|
|
|
+const onlineUsersElement = document.querySelector("#onlineUsers h4");
|
|
|
// --- Reward Elements ---
|
|
// --- Reward Elements ---
|
|
|
const rewardBtn = document.getElementById('rewardBtn');
|
|
const rewardBtn = document.getElementById('rewardBtn');
|
|
|
const rewardModal = document.getElementById('rewardModal');
|
|
const rewardModal = document.getElementById('rewardModal');
|
|
@@ -189,6 +190,9 @@ function initializeWebSocket() {
|
|
|
username: chatUserName
|
|
username: chatUserName
|
|
|
}));
|
|
}));
|
|
|
}
|
|
}
|
|
|
|
|
+ const userNumber = getUserList().then(users => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
+ });
|
|
|
chatWebsocket.onmessage = (event) => {
|
|
chatWebsocket.onmessage = (event) => {
|
|
|
const data = JSON.parse(event.data);
|
|
const data = JSON.parse(event.data);
|
|
|
if (data.type === "message") {
|
|
if (data.type === "message") {
|
|
@@ -196,9 +200,15 @@ function initializeWebSocket() {
|
|
|
}
|
|
}
|
|
|
else if (data.type === "join") {
|
|
else if (data.type === "join") {
|
|
|
newUserInChat(data.username);
|
|
newUserInChat(data.username);
|
|
|
|
|
+ const userNumber = getUserList().then(users => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
else if (data.type === "leave") {
|
|
else if (data.type === "leave") {
|
|
|
userLeftChat(data.username);
|
|
userLeftChat(data.username);
|
|
|
|
|
+ const userNumber = getUserList().then(users => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
else if (data.type === "mentioned") {
|
|
else if (data.type === "mentioned") {
|
|
|
if (data.username && data.username !== chatUserName) return; // not for me
|
|
if (data.username && data.username !== chatUserName) return; // not for me
|
|
@@ -277,7 +287,12 @@ function initializeChat() {
|
|
|
const userItem = document.createElement("button");
|
|
const userItem = document.createElement("button");
|
|
|
userItem.type = "button";
|
|
userItem.type = "button";
|
|
|
userItem.onclick = () => {
|
|
userItem.onclick = () => {
|
|
|
- chatInputElement.value = chatInputElement.value.replace(lastWord, `@${user}`);
|
|
|
|
|
|
|
+ // Replace the last occurrence of lastWord with @user
|
|
|
|
|
+ const inputValue = chatInputElement.value;
|
|
|
|
|
+ const lastWordIndex = inputValue.lastIndexOf(lastWord);
|
|
|
|
|
+ if (lastWordIndex !== -1) {
|
|
|
|
|
+ chatInputElement.value = inputValue.slice(0, lastWordIndex) + `@${user}` + inputValue.slice(lastWordIndex + lastWord.length);
|
|
|
|
|
+ }
|
|
|
userList.classList.add("hidden");
|
|
userList.classList.add("hidden");
|
|
|
chatInputElement.focus();
|
|
chatInputElement.focus();
|
|
|
};
|
|
};
|
|
@@ -1009,7 +1024,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
|
|
|
|
createGlobalLoader();
|
|
createGlobalLoader();
|
|
|
// Uncomment these lines when ready to initialize the full app:
|
|
// Uncomment these lines when ready to initialize the full app:
|
|
|
- initializeLoginModal();
|
|
|
|
|
|
|
+ // initializeLoginModal();
|
|
|
// hideGUI();
|
|
// hideGUI();
|
|
|
// initializeApp();
|
|
// initializeApp();
|
|
|
});
|
|
});
|