83 lines
No EOL
2.9 KiB
HTML
83 lines
No EOL
2.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Minecraft Twitch Chat Overlay</title>
|
|
<link rel="stylesheet" href="/static/css/style.css"> <!-- Link to external CSS -->
|
|
<style>
|
|
.message {
|
|
transition: opacity 1s, height 1s, margin 1s, padding 1s;
|
|
overflow: hidden;
|
|
}
|
|
.fade-out {
|
|
opacity: 0;
|
|
height: 0;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="chat"></div>
|
|
<script>
|
|
// Extract the channel name from the URL
|
|
const channel = window.location.pathname.split('/')[2];
|
|
|
|
// Store the last set of messages to avoid reloading the same ones
|
|
let lastMessages = [];
|
|
|
|
// Function to fetch chat messages
|
|
async function fetchChat() {
|
|
const response = await fetch(`/chat/${channel}`);
|
|
const data = await response.json();
|
|
const chat = document.getElementById('chat');
|
|
|
|
// Check if messages have changed
|
|
if (JSON.stringify(data.messages) !== JSON.stringify(lastMessages)) {
|
|
lastMessages = data.messages;
|
|
|
|
// Clear existing messages
|
|
chat.innerHTML = '';
|
|
|
|
// Add new messages with fade-in animation
|
|
data.messages.forEach((msg, index) => {
|
|
const messageElement = document.createElement('div');
|
|
messageElement.classList.add('message');
|
|
messageElement.textContent = msg;
|
|
messageElement.timestamp = Date.now(); // Store the timestamp
|
|
|
|
chat.appendChild(messageElement);
|
|
});
|
|
|
|
// Scroll to the bottom
|
|
chat.scrollTop = chat.scrollHeight;
|
|
}
|
|
}
|
|
|
|
// Function to fade out old messages
|
|
function fadeOutOldMessages() {
|
|
const messages = document.querySelectorAll('#chat .message');
|
|
const now = Date.now();
|
|
const fadeOutDuration = 10000; // 10 seconds
|
|
|
|
messages.forEach(message => {
|
|
const age = now - message.timestamp;
|
|
if (age > fadeOutDuration) {
|
|
message.classList.add('fade-out');
|
|
// Remove the element from the DOM after the transition ends
|
|
message.addEventListener('transitionend', () => {
|
|
message.remove();
|
|
}, { once: true });
|
|
}
|
|
});
|
|
}
|
|
|
|
// Fetch chat messages every second
|
|
setInterval(fetchChat, 1000);
|
|
|
|
// Check and fade out old messages every second
|
|
setInterval(fadeOutOldMessages, 1000);
|
|
</script>
|
|
</body>
|
|
</html> |