GrandTabernacleAutoVI/public_html/js/phone.js

44 lines
842 B
JavaScript
Raw Normal View History

2023-12-11 15:24:48 +01:00
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.innerHTML = message.title;
let p = document.createElement("p");
p.className = "messageContent";
p.innerHTML = message.content;
msg.appendChild(h2);
msg.appendChild(p);
document.getElementById("chatMessages").appendChild(msg);
}
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 = '';
}
}
}
}