HTMLify
Mc
Views: 855 | Author: djdj
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>MyChat</title> <style> body { margin: 0; padding: 0; font-family: Arial, sans-serif; } #chat-container { display: flex; flex-direction: column; height: 92vh; } #header { display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #eee; } #user-info { display: flex; align-items: center; } #icons { display: flex; align-items: center; } #messages { flex: 1; overflow-y: auto; padding: 10px; background-color: #f2f2f2; } #input-container { display: flex; align-items: center; padding: 10px; background-color: #f5f5f5; } #message-input { flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 4px; margin-right: 10px; } #emoji-btn, #send-btn { padding: 8px; cursor: pointer; } #options-menu { position: absolute; top: 30px; right: 10px; display: none; background-color: #fff; border: 1px solid #ccc; padding: 10px; } .option { padding: 8px; cursor: pointer; } #messages { flex: 1; overflow-y: auto; padding: 10px; } #right-aligned-msgs { display: flex; flex-direction: column; align-items: flex-start; } #right-aligned-msg { display: flex; flex-direction: column; align-items: flex-end; } .m{ display: inline; flex-direction: column; align-items: right; background-color: #ddd; border-radius: 10px; padding: 8px; margin: 5px; } #phone-icon{ font-size: 20px; text-decoration: none; } #options-icon{ font-size:30px; font-weight:bold; } a:link { text-decoration: none; } </style> </head> <body> <div id="chat-container"> <div id="header"> <div id="user-info"> <a href="https://htmlify.artizote.com/djdj/sabkacode.png"><img src="https://htmlify.artizote.com/djdj/sabkacode.png" alt="User Pic" style="border-radius: 50%; width: 40px; height: 40px; margin-right: 10px;"></a> <span><h3>SabkaCode</h3></span> </div> <div id="icons"> <b><span id="phone-icon"><a href="https://whatsapp.com/channel/0029VaElLRrAYlUMk0qIHX1G">📞</a></span></b><pre> </pre> <b><span id="options-icon">⋮</span></b> <div id="options-menu"> <div class="option" id="deletechat">Delete Chat</div> <div class="option">Option 2</div> <div class="option">Option 3</div> <div class="option">Option 4</div> <div class="option">Option 5</div> </div> </div> </div> <div id="messages"> <div id="right-aligned-msgs"> <div class="m">Hello!</div> <div class="m">How are you?</div> <div class="m">Nice to meet you 🙂</div> </div> <div id="right-aligned-msg"> </div> </div> <div id="input-container"> <input type="text" id="message-input" placeholder="Type your message here"> <span id="send-btn" onclick="sendMessage()">Send</span> </div> </div> <script> const optionsIcon = document.getElementById('options-icon'); const optionsMenu = document.getElementById('options-menu'); const emojiBtn = document.getElementById('emoji-btn'); const messagesContainer = document.getElementById('right-aligned-msg'); const messageInput = document.getElementById('message-input'); const sendBtn = document.getElementById('send-btn'); optionsIcon.addEventListener('click', () => { optionsMenu.style.display = optionsMenu.style.display === 'inline' ? 'none' : 'inline'; }); document.addEventListener('click', (event) => { if (!event.target.matches('#options-icon')) { optionsMenu.style.display = 'none'; } }); window.onload = () => { const storedMessages = localStorage.getItem('chatMessages'); if (storedMessages) { messagesContainer.innerHTML = storedMessages; } }; function sendMessage() { const trimmedMessage = messageInput.value.trim(); if (trimmedMessage !== '') { const newMessage = document.createElement('div'); newMessage.textContent = trimmedMessage; newMessage.className = 'm'; messagesContainer.appendChild(newMessage); messageInput.value = ''; sendBtn.disabled = true; localStorage.setItem('chatMessages', messagesContainer.innerHTML); } } messageInput.addEventListener('input', () => { sendBtn.disabled = messageInput.value.trim() === ''; }); messageInput.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !sendBtn.disabled) { sendMessage(); } }); document.getElementById("deletechat").addEventListener("click", function(event) { event.preventDefault(); var chats = document.getElementsByClassName("m"); while(chats[0]) { chats[0].parentNode.removeChild(chats[0]); } }); </script> </body> </html> |