willy.club/views/pages/willychat/messages.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2023-01-22 09:47:36 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<style>
div {
border: 1px solid silver;
margin-bottom: 8px;
padding: 8px;
background: rgba(0, 0, 0, 0.75);
color: white;
}
div > small {
color: gray;
}
div > p {
margin: 0;
margin-top: 8px;
}
</style>
<?php foreach($messages as $message): ?>
<div>
<small><?=gmdate("D M j G:i:s Y", $message['date']);?> <?=htmlspecialchars($message['nick'])?> says:</small>
<p><?=htmlspecialchars($message['text'])?></p>
</div>
<?php endforeach; ?>
<script>
let hash = '';
setInterval(async () => {
let new_hash = await fetch('sync').then((response) => response.json());
if (hash == '') {
hash = new_hash;
}
if (new_hash !== hash) {
document.location.reload();
}
}, 2000);
</script>
</body>
</html>