148 lines
4.9 KiB
JavaScript
148 lines
4.9 KiB
JavaScript
let messages = [
|
||
"I wondered why the baseball was getting bigger. Then it hit me.",
|
||
"Police were called to a day care, where a three-year-old was resisting a rest.",
|
||
"Did you hear about the guy whose whole left side was cut off? He’s all right now.",
|
||
"The roundest knight at King Arthur’s round table was Sir Cumference.",
|
||
"To write with a broken pencil is pointless.",
|
||
"When fish are in schools they sometimes take debate.",
|
||
"The short fortune teller who escaped from prison was a small medium at large.",
|
||
"A thief who stole a calendar… got twelve months.",
|
||
"A thief fell and broke his leg in wet cement. He became a hardened criminal.",
|
||
"Thieves who steal corn from a garden could be charged with stalking.",
|
||
"When the smog lifts in Los Angeles , U. C. L. A.",
|
||
"The math professor went crazy with the blackboard. He did a number on it.",
|
||
"The professor discovered that his theory of earthquakes was on shaky ground.",
|
||
"The dead batteries were given out free of charge.",
|
||
"If you take a laptop computer for a run you could jog your memory.",
|
||
"A dentist and a manicurist fought tooth and nail.",
|
||
"A bicycle can’t stand alone; it is two tired.",
|
||
"A will is a dead giveaway.",
|
||
"Time flies like an arrow; fruit flies like a banana.",
|
||
"A backward poet writes inverse.",
|
||
"In a democracy it’s your vote that counts; in feudalism, it’s your Count that votes.",
|
||
"A chicken crossing the road: poultry in motion.",
|
||
"If you don’t pay your exorcist you can get repossessed.",
|
||
"With her marriage she got a new name and a dress.",
|
||
"Show me a piano falling down a mine shaft and I’ll show you A-flat miner.",
|
||
"When a clock is hungry it goes back four seconds.",
|
||
"The guy who fell onto an upholstery machine was fully recovered.",
|
||
"A grenade fell onto a kitchen floor in France and resulted in Linoleum Blownapart.",
|
||
"You are stuck with your debt if you can’t budge it.",
|
||
"Local Area Network in Australia : The LAN down under.",
|
||
"He broke into song because he couldn’t find the key.",
|
||
"A calendar’s days are numbered."
|
||
];
|
||
|
||
let nicks = [
|
||
"Edvard Force",
|
||
"Диванный Воин",
|
||
"Yoshka's Cat",
|
||
"XAOSHammer",
|
||
"Kino Konformist" ];
|
||
|
||
const chatwin = document.getElementById("chatwin");
|
||
const anchor = document.getElementById("anchor");
|
||
|
||
function randomMessage() {
|
||
return messages[(Math.random() * messages.length) | 0];
|
||
}
|
||
function randomNick() {
|
||
return nicks[(Math.random() * nicks.length) | 0];
|
||
}
|
||
|
||
function randomChat() { if (Math.random() * 2 > 1) {return "tg"} else { return "yt" } }
|
||
|
||
function goDown() {
|
||
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
|
||
}
|
||
|
||
function removeElementsByClass(className){
|
||
const elements = document.getElementsByClassName(className);
|
||
while(elements.length > 15){
|
||
elements[0].parentNode.removeChild(elements[0]);
|
||
}
|
||
}
|
||
|
||
function createChatLine() {
|
||
|
||
const nm = document.createElement("div");
|
||
nm.className = "nameline " + randomChat();
|
||
nm.innerHTML = randomNick();
|
||
|
||
const msg = document.createElement("div");
|
||
msg.className = "msgline";
|
||
msg.innerHTML = randomMessage();
|
||
|
||
const rw = document.createElement("div");
|
||
rw.className = "chatRow";
|
||
rw.appendChild(nm);
|
||
rw.appendChild(msg);
|
||
console.log(rw);
|
||
|
||
chatwin.insertBefore(rw, anchor);
|
||
|
||
|
||
goDown();
|
||
}
|
||
|
||
|
||
function createNewLine(json) {
|
||
|
||
json.forEach(element => {
|
||
|
||
//checking new IDs on screen and print
|
||
|
||
//const elements = document.getElementsByName(element["id"]);
|
||
//if (elements.length > 0) { //if this id is present on screen
|
||
|
||
let curline = document.getElementById(element["id"])
|
||
if (curline) {
|
||
curline.innerHTML = element["msg"]
|
||
return;
|
||
}; //Updating text...
|
||
|
||
const nm = document.createElement("div");
|
||
nm.className = "nameline " + element["type"];
|
||
nm.innerHTML = element["sendr"];
|
||
if (element["type"] == "donate") { nm.innerHTML = nm.innerHTML + '<br><p style="color: red">' + element['amount']+"</p>" }
|
||
|
||
const msg = document.createElement("div");
|
||
msg.className = "msgline";
|
||
msg.innerHTML = element["msg"];
|
||
msg.setAttribute("id", element["id"]);
|
||
if (element["type"] == "donate") { msg.style="background-color: #0000FF20" }
|
||
|
||
|
||
const rw = document.createElement("div");
|
||
rw.className = "chatRow";
|
||
rw.setAttribute("name", element["id"]);
|
||
|
||
rw.appendChild(nm);
|
||
rw.appendChild(msg);
|
||
//console.log(rw);
|
||
|
||
chatwin.insertBefore(rw, anchor);
|
||
|
||
|
||
});
|
||
|
||
|
||
|
||
}
|
||
|
||
function requestNewLines() {
|
||
|
||
var request = new XMLHttpRequest();
|
||
request.open('GET', "http://localhost:8008/");
|
||
request.responseType = 'json';
|
||
request.send();
|
||
|
||
request.onload = function() {
|
||
var chatJSON = request.response;
|
||
createNewLine(chatJSON);
|
||
goDown();
|
||
}
|
||
|
||
}
|
||
|
||
setInterval(requestNewLines,1000); |