diff --git a/api.php b/api.php new file mode 100644 index 0000000..45728c4 --- /dev/null +++ b/api.php @@ -0,0 +1,23 @@ + $response]); +} else { + // Wenn keine POST-Anfrage, senden Sie einen Fehler + header('HTTP/1.1 405 Method Not Allowed'); + echo 'Nur POST-Anfragen sind erlaubt.'; +} +?> \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 0000000..d896c1f --- /dev/null +++ b/config.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..4fd4f7e --- /dev/null +++ b/index.html @@ -0,0 +1,20 @@ + + + + + + ChatGPT Assistent + + + +
+

ChatGPT Assistent

+
+
+ + +
+
+ + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..d422a36 --- /dev/null +++ b/script.js @@ -0,0 +1,41 @@ +document.addEventListener('DOMContentLoaded', () => { + const chatForm = document.getElementById('chat-form'); + const userInput = document.getElementById('user-input'); + const chatMessages = document.getElementById('chat-messages'); + + chatForm.addEventListener('submit', async (e) => { + e.preventDefault(); + const message = userInput.value.trim(); + if (message) { + addMessage('User', message); + userInput.value = ''; + + try { + const response = await fetch('api.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ message: message }), + }); + + if (response.ok) { + const data = await response.json(); + addMessage('Assistant', data.response); + } else { + throw new Error('Fehler bei der API-Anfrage'); + } + } catch (error) { + console.error('Fehler:', error); + addMessage('System', 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.'); + } + } + }); + + function addMessage(sender, message) { + const messageElement = document.createElement('div'); + messageElement.innerHTML = `${sender}: ${message}`; + chatMessages.appendChild(messageElement); + chatMessages.scrollTop = chatMessages.scrollHeight; + } +}); \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..6e6b460 --- /dev/null +++ b/styles.css @@ -0,0 +1,54 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 0; +} + +.chat-container { + max-width: 800px; + margin: 20px auto; + background-color: white; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + padding: 20px; +} + +h1 { + text-align: center; + color: #333; +} + +#chat-messages { + height: 400px; + overflow-y: auto; + border: 1px solid #ddd; + padding: 10px; + margin-bottom: 20px; +} + +#chat-form { + display: flex; +} + +#user-input { + flex-grow: 1; + padding: 10px; + font-size: 16px; + border: 1px solid #ddd; + border-radius: 5px 0 0 5px; +} + +button { + padding: 10px 20px; + font-size: 16px; + background-color: #007bff; + color: white; + border: none; + border-radius: 0 5px 5px 0; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} \ No newline at end of file