Spaces:
Running
Running
تازیخچه چتها را هم نمایش بده
Browse files- index.html +117 -8
- style.css +26 -1
index.html
CHANGED
|
@@ -29,8 +29,8 @@
|
|
| 29 |
<custom-navbar></custom-navbar>
|
| 30 |
|
| 31 |
<main class="flex-1 container mx-auto px-4 py-8">
|
| 32 |
-
|
| 33 |
-
|
| 34 |
<div class="flex items-center gap-3">
|
| 35 |
<div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
| 36 |
<i data-feather="message-square"></i>
|
|
@@ -38,9 +38,20 @@
|
|
| 38 |
<h2 class="text-xl font-bold">Chatty McBotface</h2>
|
| 39 |
</div>
|
| 40 |
</div>
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
<div class="w-full flex justify-center">
|
| 45 |
<div class="bg-gray-100 rounded-lg p-4 max-w-[80%] text-center">
|
| 46 |
<p class="text-gray-600">Hi there! I'm your friendly AI assistant. How can I help you today?</p>
|
|
@@ -77,9 +88,105 @@
|
|
| 77 |
<script>
|
| 78 |
feather.replace();
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
// Simple chatbot logic
|
| 81 |
document.getElementById('chat-form').addEventListener('submit', function(e) {
|
| 82 |
-
|
| 83 |
const input = document.getElementById('user-input');
|
| 84 |
const message = input.value.trim();
|
| 85 |
|
|
@@ -99,13 +206,15 @@
|
|
| 99 |
];
|
| 100 |
const botResponse = responses[Math.floor(Math.random() * responses.length)] +
|
| 101 |
" This is a simulated response. In a real implementation, this would connect to an AI API like OpenAI.";
|
| 102 |
-
|
| 103 |
addMessage(botResponse, 'bot');
|
|
|
|
| 104 |
}, 1000);
|
| 105 |
}
|
| 106 |
});
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
const messagesContainer = document.getElementById('chat-messages');
|
| 110 |
const messageDiv = document.createElement('div');
|
| 111 |
messageDiv.className = `w-full flex ${sender === 'user' ? 'justify-end' : 'justify-start'}`;
|
|
|
|
| 29 |
<custom-navbar></custom-navbar>
|
| 30 |
|
| 31 |
<main class="flex-1 container mx-auto px-4 py-8">
|
| 32 |
+
<div id="chat-container" class="bg-white rounded-lg shadow-lg h-[70vh] overflow-hidden flex flex-col relative">
|
| 33 |
+
<div class="bg-gradient-to-r from-primary-500 to-secondary-500 p-4 text-white">
|
| 34 |
<div class="flex items-center gap-3">
|
| 35 |
<div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
| 36 |
<i data-feather="message-square"></i>
|
|
|
|
| 38 |
<h2 class="text-xl font-bold">Chatty McBotface</h2>
|
| 39 |
</div>
|
| 40 |
</div>
|
| 41 |
+
<div class="absolute top-0 left-0 w-full z-10 bg-gradient-to-r from-primary-500 to-secondary-500 text-white px-4 py-2 flex justify-between items-center">
|
| 42 |
+
<button id="history-btn" class="flex items-center gap-2 hover:bg-white/10 px-3 py-1 rounded transition">
|
| 43 |
+
<i data-feather="clock"></i>
|
| 44 |
+
<span>History</span>
|
| 45 |
+
</button>
|
| 46 |
+
<div id="history-dropdown" class="hidden absolute top-full left-0 mt-1 w-64 bg-white rounded-lg shadow-lg z-20">
|
| 47 |
+
<div class="p-3 border-b border-gray-200 font-medium text-gray-700">Conversation History</div>
|
| 48 |
+
<div id="history-list" class="max-h-60 overflow-y-auto">
|
| 49 |
+
<!-- History items will be added here -->
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
<div id="chat-messages" class="flex-1 overflow-y-auto p-4 space-y-4 mt-12">
|
| 54 |
+
<!-- Messages will be inserted here -->
|
| 55 |
<div class="w-full flex justify-center">
|
| 56 |
<div class="bg-gray-100 rounded-lg p-4 max-w-[80%] text-center">
|
| 57 |
<p class="text-gray-600">Hi there! I'm your friendly AI assistant. How can I help you today?</p>
|
|
|
|
| 88 |
<script>
|
| 89 |
feather.replace();
|
| 90 |
|
| 91 |
+
// Chat history functionality
|
| 92 |
+
const historyBtn = document.getElementById('history-btn');
|
| 93 |
+
const historyDropdown = document.getElementById('history-dropdown');
|
| 94 |
+
const historyList = document.getElementById('history-list');
|
| 95 |
+
|
| 96 |
+
// Toggle history dropdown
|
| 97 |
+
historyBtn.addEventListener('click', () => {
|
| 98 |
+
historyDropdown.classList.toggle('hidden');
|
| 99 |
+
});
|
| 100 |
+
|
| 101 |
+
// Close dropdown when clicking outside
|
| 102 |
+
document.addEventListener('click', (e) => {
|
| 103 |
+
if (!historyBtn.contains(e.target) && !historyDropdown.contains(e.target)) {
|
| 104 |
+
historyDropdown.classList.add('hidden');
|
| 105 |
+
}
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
// Load saved conversations
|
| 109 |
+
function loadChatHistory() {
|
| 110 |
+
const history = JSON.parse(localStorage.getItem('chatHistory') || '[]');
|
| 111 |
+
historyList.innerHTML = '';
|
| 112 |
+
|
| 113 |
+
if (history.length === 0) {
|
| 114 |
+
historyList.innerHTML = '<div class="p-3 text-gray-500 text-center">No previous conversations</div>';
|
| 115 |
+
return;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
history.forEach((conv, index) => {
|
| 119 |
+
const historyItem = document.createElement('div');
|
| 120 |
+
historyItem.className = 'p-3 border-b border-gray-100 hover:bg-gray-50 cursor-pointer';
|
| 121 |
+
historyItem.innerHTML = `
|
| 122 |
+
<div class="font-medium text-gray-800 truncate">${conv.preview || 'Conversation'}</div>
|
| 123 |
+
<div class="text-xs text-gray-500">${new Date(conv.timestamp).toLocaleString()}</div>
|
| 124 |
+
`;
|
| 125 |
+
|
| 126 |
+
historyItem.addEventListener('click', () => {
|
| 127 |
+
loadConversation(index);
|
| 128 |
+
historyDropdown.classList.add('hidden');
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
historyList.appendChild(historyItem);
|
| 132 |
+
});
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Save current conversation
|
| 136 |
+
function saveConversation() {
|
| 137 |
+
const messages = document.getElementById('chat-messages');
|
| 138 |
+
const preview = messages.lastElementChild?.textContent?.trim().substring(0, 50) || 'New conversation';
|
| 139 |
+
|
| 140 |
+
const history = JSON.parse(localStorage.getItem('chatHistory') || '[]');
|
| 141 |
+
history.unshift({
|
| 142 |
+
messages: Array.from(messages.children).map(el => ({
|
| 143 |
+
text: el.querySelector('p')?.textContent,
|
| 144 |
+
sender: el.classList.contains('justify-end') ? 'user' : 'bot'
|
| 145 |
+
})),
|
| 146 |
+
preview,
|
| 147 |
+
timestamp: new Date().toISOString()
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
// Keep only last 10 conversations
|
| 151 |
+
localStorage.setItem('chatHistory', JSON.stringify(history.slice(0, 10)));
|
| 152 |
+
loadChatHistory();
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// Load a specific conversation
|
| 156 |
+
function loadConversation(index) {
|
| 157 |
+
const history = JSON.parse(localStorage.getItem('chatHistory') || '[]');
|
| 158 |
+
const conv = history[index];
|
| 159 |
+
|
| 160 |
+
if (!conv) return;
|
| 161 |
+
|
| 162 |
+
const messagesContainer = document.getElementById('chat-messages');
|
| 163 |
+
messagesContainer.innerHTML = '';
|
| 164 |
+
|
| 165 |
+
conv.messages.forEach(msg => {
|
| 166 |
+
const messageDiv = document.createElement('div');
|
| 167 |
+
messageDiv.className = `w-full flex ${msg.sender === 'user' ? 'justify-end' : 'justify-start'}`;
|
| 168 |
+
|
| 169 |
+
const bubbleClass = msg.sender === 'user'
|
| 170 |
+
? 'bg-primary-500 text-white rounded-br-none'
|
| 171 |
+
: 'bg-gray-100 text-gray-800 rounded-bl-none';
|
| 172 |
+
|
| 173 |
+
messageDiv.innerHTML = `
|
| 174 |
+
<div class="max-w-[80%] rounded-lg p-4 ${bubbleClass}">
|
| 175 |
+
<p>${msg.text}</p>
|
| 176 |
+
</div>
|
| 177 |
+
`;
|
| 178 |
+
|
| 179 |
+
messagesContainer.appendChild(messageDiv);
|
| 180 |
+
});
|
| 181 |
+
|
| 182 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 183 |
+
}
|
| 184 |
+
// Initialize chat history
|
| 185 |
+
loadChatHistory();
|
| 186 |
+
|
| 187 |
// Simple chatbot logic
|
| 188 |
document.getElementById('chat-form').addEventListener('submit', function(e) {
|
| 189 |
+
e.preventDefault();
|
| 190 |
const input = document.getElementById('user-input');
|
| 191 |
const message = input.value.trim();
|
| 192 |
|
|
|
|
| 206 |
];
|
| 207 |
const botResponse = responses[Math.floor(Math.random() * responses.length)] +
|
| 208 |
" This is a simulated response. In a real implementation, this would connect to an AI API like OpenAI.";
|
|
|
|
| 209 |
addMessage(botResponse, 'bot');
|
| 210 |
+
saveConversation();
|
| 211 |
}, 1000);
|
| 212 |
}
|
| 213 |
});
|
| 214 |
|
| 215 |
+
// Save conversation when leaving page
|
| 216 |
+
window.addEventListener('beforeunload', saveConversation);
|
| 217 |
+
function addMessage(text, sender) {
|
| 218 |
const messagesContainer = document.getElementById('chat-messages');
|
| 219 |
const messageDiv = document.createElement('div');
|
| 220 |
messageDiv.className = `w-full flex ${sender === 'user' ? 'justify-end' : 'justify-start'}`;
|
style.css
CHANGED
|
@@ -17,10 +17,35 @@ body {
|
|
| 17 |
#chat-messages > div {
|
| 18 |
animation: fadeIn 0.3s ease-out;
|
| 19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
/* Custom scrollbar for chat */
|
| 22 |
#chat-messages::-webkit-scrollbar {
|
| 23 |
-
|
| 24 |
}
|
| 25 |
|
| 26 |
#chat-messages::-webkit-scrollbar-track {
|
|
|
|
| 17 |
#chat-messages > div {
|
| 18 |
animation: fadeIn 0.3s ease-out;
|
| 19 |
}
|
| 20 |
+
/* History dropdown styles */
|
| 21 |
+
#history-dropdown {
|
| 22 |
+
max-height: 70vh;
|
| 23 |
+
overflow: hidden;
|
| 24 |
+
display: flex;
|
| 25 |
+
flex-direction: column;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
#history-list {
|
| 29 |
+
scrollbar-width: thin;
|
| 30 |
+
scrollbar-color: #c1c1c1 #f1f1f1;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
#history-list::-webkit-scrollbar {
|
| 34 |
+
width: 6px;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
#history-list::-webkit-scrollbar-track {
|
| 38 |
+
background: #f1f1f1;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
#history-list::-webkit-scrollbar-thumb {
|
| 42 |
+
background: #c1c1c1;
|
| 43 |
+
border-radius: 3px;
|
| 44 |
+
}
|
| 45 |
|
| 46 |
/* Custom scrollbar for chat */
|
| 47 |
#chat-messages::-webkit-scrollbar {
|
| 48 |
+
width: 8px;
|
| 49 |
}
|
| 50 |
|
| 51 |
#chat-messages::-webkit-scrollbar-track {
|