GrandTabernacleAutoVI/public_html/js/phone.js
Killian Marty a7014b48ec XSS fix
2023-12-13 23:14:45 +01:00

57 lines
No EOL
1.2 KiB
JavaScript

class Phone{
constructor(){
this.position = 0;
this.messages = [];
}
addMessage(message){
this.messages.push(message);
let msg = document.createElement("div");
msg.className = "message";
let h2 = document.createElement("h2");
h2.className = "messageTitle";
h2.innerText = message.title;
let p = document.createElement("p");
p.className = "messageContent";
p.innerText = message.content;
msg.appendChild(h2);
msg.appendChild(p);
let chatMessages = document.getElementById("chatMessages");
chatMessages.appendChild(msg);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
sendMessage(title, content){
let message = {
title: player.name,
content: content
}
this.addMessage(message);
net.sendMessage(title, content);
}
keyPress(input){
if(event.key=='Enter'){
if(input.value!=''){
this.sendMessage(player.name, input.value);
input.value = '';
input.blur()
}
}
}
changePosition(){
if(this.position == 0){
document.getElementById("phoneContainer").className = "visible";
this.position = 1;
}else{
document.getElementById("phoneContainer").className = "hidden";
this.position = 0;
}
}
}