i got banned from lemmy.cafe for saying pineapple pizza bad, definitely avoid it
is there anyone for center leaning folks?
something something genocide
exactly that’s why it will always lag behind
but how to find groups?
any proof that most muslims have bad belief?
i upvoted you even if i disagree because i like to engage opposite of my belief
yeah that’s my middle name, i don’t think i can change your mind but i will say this that majority of followers of islam have bad beliefs
some say fascism is a form of religion
no i am genuinely curious
not necessarily
thoughts mean when people think about to give opinion about something
what about established accounts?
is it wrong?
yes i meant separate instance also we just have to put this, dark souls wiki also uses it
You don’t need to rewrite the whole page—just inject the pieces for Socket .io and your chat UI where indicated. Here’s exactly what to add or change in existing HTML (THIS PAGE):
Find the closing </head>
tag and just before it insert:
<!-- Socket.IO client library (served automatically by your server) -->
<script src="/socket.io/socket.io.js"></script>
<!-- Optional: simple styles for the chat box -->
<style>
#chat-container {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
max-height: 400px;
background: white;
border: 1px solid #ccc;
display: flex;
flex-direction: column;
font-family: sans-serif;
z-index: 1000;
}
#chat-messages {
flex: 1;
overflow-y: auto;
padding: 8px;
}
#chat-form {
display: flex;
border-top: 1px solid #eee;
}
#chat-input {
flex: 1;
border: none;
padding: 8px;
}
#chat-send {
border: none;
padding: 8px 12px;
cursor: pointer;
}
</style>
</head>
Find the closing </body>
tag and just before it paste:
<!-- Chat widget -->
<div id="chat-container">
<div id="chat-messages"></div>
<form id="chat-form">
<input id="chat-input" autocomplete="off" placeholder="Type a message…" />
<button type="submit" id="chat-send">Send</button>
</form>
</div>
Right below that (still before </body>
), add:
<script>
// connect using the global io() function
const socket = io();
const form = document.getElementById('chat-form');
const input = document.getElementById('chat-input');
const messages = document.getElementById('chat-messages');
// render incoming messages
socket.on('message', ({ from, text }) => {
const div = document.createElement('div');
div.textContent = from + ': ' + text;
messages.appendChild(div);
messages.scrollTop = messages.scrollHeight;
});
// on submit send to server
form.addEventListener('submit', e => {
e.preventDefault();
const msg = input.value.trim();
if (!msg) return;
socket.emit('message', msg);
input.value = '';
});
</script>
</body>
</html>
On your Node/Express server (the same one you use to serve the Lemmy/lemm.ee front-end), you need to:
Install Socket.IO:
npm install socket.io
Hook it up to your HTTP server (roughly as in the example I shared before), making sure you share sessions so only logged-in users connect.
The minimal changes in your server.js
(or equivalent) are:
const http = require('http');
const socketIO = require('socket.io');
// … your existing Express `app`
const server = http.createServer(app);
const io = socketIO(server);
// (if you have session middleware already:)
io.use((socket, next) => {
// reuse your Express session middleware here…
sessionMiddleware(socket.request, socket.request.res || {}, next);
});
io.on('connection', socket => {
const user = socket.request.session.user;
if (!user) return socket.disconnect(true);
socket.broadcast.emit('message', {
from: 'SYSTEM',
text: `${user.name} joined.`
});
socket.on('message', msg => {
io.emit('message', { from: user.name, text: msg });
});
socket.on('disconnect', () => {
io.emit('message', {
from: 'SYSTEM',
text: `${user.name} left.`
});
});
});
server.listen(3000);
<script src="/socket.io/socket.io.js">
+ minimal CSS<div id="chat-container">…</div>
chat widget<script>…</script>
block to wire up io()
With those three small patches, your existing site will host a floating chat box that’s only usable by authenticated users. Let me know if you need help wiring up the session middleware or adjusting the styles!
yea but do you think it will be a good idea?
good point
know when to be evil? i am assuming you meant to say when do we have the right to defend ourselves?
no joke, i got banned from lemmy.cafe for saying pineapple pizza bad, definitely avoid it