/
script.js
32 lines (26 loc) · 1.15 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ChatHandler, chat_names } from './ChatHandler.js';
onload = function () {
const chatlist = document.getElementById('chat-list');
const add = document.getElementById('generate-step');
const text = document.getElementById('temptext');
const templates = document.getElementsByTagName('template')[0];
const chat_item = templates.content.querySelector("li");
const chatHandler = new ChatHandler(chat_item, chatlist);
let chats = [];
add.onclick = function () {
if(Math.random()>0.75 && chats.length > 0){
let index = Math.floor(Math.random()*chats.length);
let idToDelete = chats[index];
chatHandler.deleteMsg(idToDelete);
text.innerHTML = "Deleted message from "+chat_names[idToDelete] + "<br>" + text.innerHTML;
chats.splice(index, 1);
} else{
let idOfMsg = Math.floor(Math.random()*7);
if(chats.includes(idOfMsg)===false){
chats.push(idOfMsg);
}
chatHandler.newMsg(idOfMsg);
text.innerHTML = "New message from "+chat_names[idOfMsg] + "<br>" + text.innerHTML;
}
};
};