mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 17:43:42 -05:00
Create script.js
This commit is contained in:
parent
3b03c00cbf
commit
9700af2741
1 changed files with 38 additions and 0 deletions
38
board/script.js
Normal file
38
board/script.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Generate random username
|
||||||
|
function generateRandomUsername() {
|
||||||
|
const randomNum = Math.floor(Math.random() * 100000);
|
||||||
|
return `milkenjoyer${randomNum.toString().padStart(5, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const username = generateRandomUsername();
|
||||||
|
document.getElementById('username').innerText = username;
|
||||||
|
|
||||||
|
// Handle post submission
|
||||||
|
const postForm = document.getElementById('post-form');
|
||||||
|
const postContent = document.getElementById('post-content');
|
||||||
|
const postsSection = document.getElementById('posts-section');
|
||||||
|
|
||||||
|
postForm.addEventListener('submit', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const content = postContent.value.trim();
|
||||||
|
if (!content) return;
|
||||||
|
|
||||||
|
const post = document.createElement('div');
|
||||||
|
post.classList.add('post');
|
||||||
|
|
||||||
|
const postUsername = document.createElement('p');
|
||||||
|
postUsername.classList.add('username');
|
||||||
|
postUsername.innerText = username;
|
||||||
|
post.appendChild(postUsername);
|
||||||
|
|
||||||
|
const postContentEl = document.createElement('p');
|
||||||
|
postContentEl.classList.add('content');
|
||||||
|
postContentEl.innerText = content;
|
||||||
|
post.appendChild(postContentEl);
|
||||||
|
|
||||||
|
postsSection.prepend(post);
|
||||||
|
postContent.value = ''; // Clear post content
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue