generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsite.html
159 lines (137 loc) · 3.87 KB
/
Website.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<title>Chat Room</title>
<style>
body {
background-color: #36393f;
color: #ffffff;
font-family: Arial, sans-serif;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
.chat-box {
width: 500px;
height: 500px;
border: 1px solid #72767d;
overflow-y: scroll;
padding: 10px;
margin-bottom: 20px;
background-color: #2f3136;
}
.chat-message {
margin-bottom: 10px;
}
.chat-message .username {
font-weight: bold;
color: #ffffff;
}
.chat-message .content {
margin-left: 10px;
}
.input-box {
display: flex;
justify-content: center;
align-items: center;
}
.input-box input[type="text"] {
width: 400px;
height: 40px;
padding: 5px;
border: 1px solid #72767d;
border-radius: 4px;
background-color: #2f3136;
color: #ffffff;
}
.input-box input[type="submit"] {
height: 40px;
padding: 5px 10px;
margin-left: 10px;
border: none;
background-color: #7289da;
color: #ffffff;
cursor: pointer;
border-radius: 4px;
}
.input-box input[type="submit"]:hover {
background-color: #5f73bc;
}
</style>
</head>
<body>
<div class="container">
<div class="chat-box" id="chatBox"></div>
<div class="input-box">
<input type="text" id="messageInput" placeholder="Type your message">
<input type="submit" value="Send" onclick="sendMessage()">
</div>
</div>
<script>
var username = localStorage.getItem('username');
if (!username) {
username = prompt("Enter your username:");
localStorage.setItem('username', username);
}
function sendMessage() {
var messageInput = document.getElementById('messageInput');
var message = messageInput.value.trim();
if (message !== '') {
var messageElement = document.createElement('div');
messageElement.className = 'chat-message';
var usernameElement = document.createElement('span');
usernameElement.className = 'username';
usernameElement.textContent = username;
var contentElement = document.createElement('span');
contentElement.className = 'content';
contentElement.textContent = message;
messageElement.appendChild(usernameElement);
messageElement.appendChild(contentElement);
var chatBox = document.getElementById('chatBox');
chatBox.appendChild(messageElement);
chatBox.scrollTop = chatBox.scrollHeight;
messageInput.value = '';
checkMentionedUser(message);
}
}
function checkMentionedUser(message) {
var words = message.split(' ');
for (var i = 0; i < words.length; i++) {
var word = words[i];
if (word.startsWith('@')) {
var mentionedUsername = word.substring(1);
showNotification(mentionedUsername);
}
}
}
function showNotification(username) {
if (Notification.permission === 'granted') {
var notification = new Notification('You were mentioned in the chat!', {
body: 'Click to view the message.',
icon: 'notification-icon.png'
});
notification.onclick = function() {
window.focus();
notification.close();
};
} else if (Notification.permission !== 'denied') {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
showNotification(username);
}
});
}
}
var messageInput = document.getElementById('messageInput');
messageInput.addEventListener('keydown', function(event) {
if (event.keyCode === 13) {
sendMessage();
}
});
</script>
</body>
</html>