-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let input = document.querySelector('input'); | ||
let button = document.querySelector('button'); | ||
let conversation = document.querySelector('.conversation'); | ||
|
||
// Retrieve the conversation history from local storage | ||
let history = JSON.parse(localStorage.getItem('conversation')) || []; | ||
|
||
// Display the conversation history | ||
for (let i = 0; i < history.length; i++) { | ||
conversation.innerHTML += `<p>${history[i]}</p>`; | ||
} | ||
|
||
button.addEventListener('click', function() { | ||
let message = input.value; | ||
conversation.innerHTML += `<p>You: ${message}</p>`; | ||
input.value = ''; | ||
|
||
// Save the conversation to local storage | ||
history.push(`You: ${message}`); | ||
localStorage.setItem('conversation', JSON.stringify(history)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Chat App</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="conversation-container"> | ||
<div class="conversation"></div> | ||
</div> | ||
<div class="input-container"> | ||
<form> | ||
<input type="text" id="message-input" placeholder="Enter your message"> | ||
<button type="submit" id="send-button">Send</button> | ||
</form> | ||
</div> | ||
|
||
<script src="chat.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* General styles */ | ||
body { | ||
background-color: #e5e5e5; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
/* Conversation container */ | ||
.conversation { | ||
padding: 20px; | ||
max-height: 80vh; | ||
overflow-y: scroll; | ||
} | ||
|
||
/* Message container */ | ||
.message { | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border-radius: 10px; | ||
font-size: 14px; | ||
} | ||
|
||
/* Sent messages */ | ||
.sent { | ||
background-color: #dcf8c6; | ||
float: right; | ||
clear: both; | ||
} | ||
|
||
/* Received messages */ | ||
.received { | ||
background-color: #fff; | ||
float: left; | ||
clear: both; | ||
} | ||
|
||
/* Input container */ | ||
.input-container { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
padding: 10px; | ||
background-color: #f8f8f8; | ||
border-top: 1px solid #ccc; | ||
} | ||
|
||
/* Input field and button */ | ||
input, button { | ||
padding: 10px; | ||
font-size: 14px; | ||
border: none; | ||
border-radius: 5px; | ||
} | ||
|
||
input { | ||
flex-grow: 1; | ||
margin-right: 10px; | ||
} | ||
|
||
button { | ||
background-color: #4caf50; | ||
color: #fff; | ||
} |