| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <title>AI Chat Support</title> |
| <style> |
| :root { |
| --bg-light: #f5f7fa; |
| --container-light: #ffffff; |
| --text-light: #333; |
| --bubble-light: #f0f2f5; |
| --me-light: #0084ff; |
| |
| --bg-dark: #121212; |
| --container-dark: #1e1e1e; |
| --text-dark: #e0e0e0; |
| --bubble-dark: #2c2c2c; |
| --me-dark: #3498db; |
| } |
| |
| body { |
| font-family: Arial, sans-serif; |
| background-color: var(--bg-light); |
| color: var(--text-light); |
| padding: 30px; |
| transition: all 0.3s ease; |
| } |
| |
| body.dark { |
| background-color: var(--bg-dark); |
| color: var(--text-dark); |
| } |
| |
| #container { |
| max-width: 800px; |
| margin: auto; |
| background-color: var(--container-light); |
| border-radius: 12px; |
| padding: 30px; |
| box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); |
| transition: background 0.3s ease; |
| } |
| |
| body.dark #container { |
| background-color: var(--container-dark); |
| } |
| |
| h1 { |
| text-align: center; |
| margin-bottom: 20px; |
| } |
| |
| #toggleMode { |
| background-color: #3498db; |
| border: none; |
| color: white; |
| padding: 10px 20px; |
| border-radius: 8px; |
| cursor: pointer; |
| float: right; |
| margin-bottom: 20px; |
| } |
| |
| #Output { |
| display: flex; |
| flex-direction: column; |
| gap: 10px; |
| max-height: 400px; |
| overflow-y: auto; |
| padding: 15px; |
| border-radius: 8px; |
| background: var(--bubble-light); |
| transition: background 0.3s ease; |
| } |
| |
| body.dark #Output { |
| background: var(--bubble-dark); |
| } |
| |
| .message { |
| display: flex; |
| max-width: 80%; |
| } |
| |
| .message.me { |
| align-self: flex-end; |
| } |
| |
| .message.other { |
| align-self: flex-start; |
| } |
| |
| .bubble { |
| padding: 10px 15px; |
| border-radius: 16px; |
| max-width: 100%; |
| word-wrap: break-word; |
| opacity: 0; |
| transform: translateY(10px); |
| animation: fadeInUp 0.4s forwards; |
| } |
| |
| .message.me .bubble { |
| background-color: var(--me-light); |
| color: white; |
| border-bottom-right-radius: 0; |
| } |
| |
| body.dark .message.me .bubble { |
| background-color: var(--me-dark); |
| } |
| |
| .message.other .bubble { |
| background-color: #ffffff; |
| color: #333; |
| border: 1px solid #dfe6e9; |
| border-left: 4px solid #3498db; |
| box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); |
| } |
| |
| body.dark .message.other .bubble { |
| background-color: #2c3e50; |
| color: #ecf0f1; |
| } |
| |
| #Input { |
| width: 100%; |
| padding: 15px; |
| font-size: 16px; |
| border: 1px solid #ccc; |
| border-radius: 8px; |
| margin-bottom: 15px; |
| } |
| |
| #sendButton { |
| padding: 10px 20px; |
| background-color: #3498db; |
| color: white; |
| border: none; |
| font-size: 16px; |
| border-radius: 8px; |
| cursor: pointer; |
| transition: background-color 0.3s ease; |
| } |
| |
| #sendButton:hover { |
| background-color: #2980b9; |
| } |
| |
| @keyframes fadeInUp { |
| to { |
| opacity: 1; |
| transform: translateY(0); |
| } |
| } |
| .dive { |
| background-color: #f0f8ff; |
| border: 2px solid #00aaff; |
| padding: 20px; |
| margin: 30px; |
| font-size: 18px; |
| text-align: center; |
| color: #333; |
| border-radius: 8px; |
| } |
| </style> |
| </head> |
| <body> |
| <div id="container"> |
| <button id="toggleMode">🌗 Toggle Mode</button> |
| <h1>AI Chat Support</h1> |
|
|
| <div id="Output"></div> |
|
|
| <label for="Input">Type your question here:</label> |
| <input id="Input" placeholder="e.g. What is Apple?" /> |
| <button id="sendButton" onclick="askGemini()">Send</button> |
| </div> |
| <div class="dive"> |
| <a href="index_vi.html">Click here to see vietnamese page</a> |
| </div> |
|
|
| <script> |
| document.getElementById("toggleMode").addEventListener("click", function () { |
| document.body.classList.toggle("dark"); |
| }); |
| |
| function askGemini() { |
| const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=AIzaSyBNxw7SIRHBzm7ALF0YTJ87_K6w1_Qc_74`; |
| const Inputs = document.getElementById("Input").value.trim(); |
| if (Inputs === "") return; |
| |
| appendMessage(Inputs, true); |
| |
| const loadingMsg = appendMessage("Thinking...", false); |
| |
| const body = { |
| contents: [ |
| { |
| parts: [ |
| { |
| text: `Your name is Teo from Vietnam. Imagine you're a professional electronics marketer, selling millions daily. Please respond to the following in English: ${Inputs}`, |
| } |
| ] |
| } |
| ] |
| }; |
| |
| fetch(url, { |
| method: "POST", |
| headers: { |
| "Content-Type": "application/json", |
| }, |
| body: JSON.stringify(body), |
| }) |
| .then((res) => res.json()) |
| .then((data) => { |
| const output = data.candidates[0].content.parts[0].text; |
| loadingMsg.querySelector(".bubble").textContent = "🤖 " + output; |
| document.getElementById("Input").value = ""; |
| }) |
| .catch((err) => { |
| console.error(err); |
| loadingMsg.querySelector(".bubble").textContent = |
| "Error calling Gemini API."; |
| }); |
| } |
| |
| document.getElementById("Input").addEventListener("keydown", function (event) { |
| if (event.key === "Enter") { |
| askGemini(); |
| } |
| }); |
| |
| function appendMessage(content, isMe) { |
| const chatBox = document.getElementById("Output"); |
| |
| const messageDiv = document.createElement("div"); |
| messageDiv.className = `message ${isMe ? "me" : "other"}`; |
| |
| const bubble = document.createElement("div"); |
| bubble.className = "bubble"; |
| bubble.textContent = content; |
| |
| messageDiv.appendChild(bubble); |
| chatBox.appendChild(messageDiv); |
| chatBox.scrollTop = chatBox.scrollHeight; |
| return messageDiv; |
| } |
| </script> |
| </body> |
| </html> |