fade out, test debug point
This commit is contained in:
parent
f5a8dc5220
commit
3c1a8696cb
2 changed files with 59 additions and 5 deletions
25
main.go
25
main.go
|
@ -64,6 +64,31 @@ func main() {
|
||||||
c.File("./static/overlay.html") // Serve the overlay HTML
|
c.File("./static/overlay.html") // Serve the overlay HTML
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Test endpoint to simulate chat messages via POST requests
|
||||||
|
r.POST("/test/:channel", func(c *gin.Context) {
|
||||||
|
channel := c.Param("channel")
|
||||||
|
var request struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(&request); err != nil {
|
||||||
|
c.JSON(400, gin.H{"error": "Invalid request body"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
messages := channelMessages[channel]
|
||||||
|
messages = append(messages, fmt.Sprintf("%s: %s", request.Username, request.Message))
|
||||||
|
if len(messages) > 100 { // Keep only the last 100 messages
|
||||||
|
messages = messages[1:]
|
||||||
|
}
|
||||||
|
channelMessages[channel] = messages
|
||||||
|
|
||||||
|
c.JSON(200, gin.H{"status": "message added"})
|
||||||
|
})
|
||||||
|
|
||||||
// Start the web server
|
// Start the web server
|
||||||
go func() {
|
go func() {
|
||||||
err := client.Connect()
|
err := client.Connect()
|
||||||
|
|
|
@ -5,6 +5,18 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Minecraft Twitch Chat Overlay</title>
|
<title>Minecraft Twitch Chat Overlay</title>
|
||||||
<link rel="stylesheet" href="/static/css/style.css"> <!-- Link to external CSS -->
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="chat"></div>
|
<div id="chat"></div>
|
||||||
|
@ -33,11 +45,7 @@
|
||||||
const messageElement = document.createElement('div');
|
const messageElement = document.createElement('div');
|
||||||
messageElement.classList.add('message');
|
messageElement.classList.add('message');
|
||||||
messageElement.textContent = msg;
|
messageElement.textContent = msg;
|
||||||
|
messageElement.timestamp = Date.now(); // Store the timestamp
|
||||||
// Fade out older messages if there are more than 10
|
|
||||||
if (data.messages.length > 10 && index < data.messages.length - 10) {
|
|
||||||
messageElement.classList.add('fade-out');
|
|
||||||
}
|
|
||||||
|
|
||||||
chat.appendChild(messageElement);
|
chat.appendChild(messageElement);
|
||||||
});
|
});
|
||||||
|
@ -47,8 +55,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Fetch chat messages every second
|
||||||
setInterval(fetchChat, 1000);
|
setInterval(fetchChat, 1000);
|
||||||
|
|
||||||
|
// Check and fade out old messages every second
|
||||||
|
setInterval(fadeOutOldMessages, 1000);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue