Update index.html
Browse files- index.html +28 -5
index.html
CHANGED
|
@@ -3,13 +3,19 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width" />
|
| 6 |
-
<title>AI Chat App</title>
|
| 7 |
<link rel="stylesheet" href="style.css" />
|
| 8 |
<script src="https://js.puter.com/v2/"></script>
|
| 9 |
</head>
|
| 10 |
|
| 11 |
<body>
|
| 12 |
-
<div id="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
<div id="messages"></div>
|
| 14 |
<div id="chat-input">
|
| 15 |
<input type="text" id="input-message" placeholder="Type a message..." />
|
|
@@ -21,11 +27,28 @@
|
|
| 21 |
|
| 22 |
<script>
|
| 23 |
const messages = [];
|
|
|
|
|
|
|
| 24 |
const messagesDiv = document.getElementById('messages');
|
| 25 |
const input = document.getElementById('input-message');
|
| 26 |
const sendBtn = document.getElementById('send-btn');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
//
|
| 29 |
function addMessage(text, sender) {
|
| 30 |
const msg = document.createElement('div');
|
| 31 |
msg.classList.add('message', sender);
|
|
@@ -34,7 +57,7 @@
|
|
| 34 |
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 35 |
}
|
| 36 |
|
| 37 |
-
//
|
| 38 |
async function sendMessage() {
|
| 39 |
const userText = input.value.trim();
|
| 40 |
if (!userText) return;
|
|
@@ -61,4 +84,4 @@
|
|
| 61 |
});
|
| 62 |
</script>
|
| 63 |
</body>
|
| 64 |
-
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width" />
|
| 6 |
+
<title>AI Chat App with Puter Auth</title>
|
| 7 |
<link rel="stylesheet" href="style.css" />
|
| 8 |
<script src="https://js.puter.com/v2/"></script>
|
| 9 |
</head>
|
| 10 |
|
| 11 |
<body>
|
| 12 |
+
<div id="auth-container">
|
| 13 |
+
<h2>Welcome to AI Chat</h2>
|
| 14 |
+
<p>Please sign in with your Puter account to continue.</p>
|
| 15 |
+
<button id="sign-in">🔐 Sign in with Puter</button>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<div id="chat-container" style="display: none;">
|
| 19 |
<div id="messages"></div>
|
| 20 |
<div id="chat-input">
|
| 21 |
<input type="text" id="input-message" placeholder="Type a message..." />
|
|
|
|
| 27 |
|
| 28 |
<script>
|
| 29 |
const messages = [];
|
| 30 |
+
const authContainer = document.getElementById('auth-container');
|
| 31 |
+
const chatContainer = document.getElementById('chat-container');
|
| 32 |
const messagesDiv = document.getElementById('messages');
|
| 33 |
const input = document.getElementById('input-message');
|
| 34 |
const sendBtn = document.getElementById('send-btn');
|
| 35 |
+
const signInBtn = document.getElementById('sign-in');
|
| 36 |
+
|
| 37 |
+
// Authenticate user
|
| 38 |
+
signInBtn.addEventListener('click', async () => {
|
| 39 |
+
try {
|
| 40 |
+
const user = await puter.auth.signIn();
|
| 41 |
+
console.log('Signed in:', user);
|
| 42 |
+
authContainer.style.display = 'none';
|
| 43 |
+
chatContainer.style.display = 'flex';
|
| 44 |
+
addMessage(`Welcome ${user.user.username || 'User'}!`, 'ai');
|
| 45 |
+
} catch (err) {
|
| 46 |
+
console.error('Sign-in failed:', err);
|
| 47 |
+
alert('Failed to sign in. Please try again.');
|
| 48 |
+
}
|
| 49 |
+
});
|
| 50 |
|
| 51 |
+
// Display message in chat
|
| 52 |
function addMessage(text, sender) {
|
| 53 |
const msg = document.createElement('div');
|
| 54 |
msg.classList.add('message', sender);
|
|
|
|
| 57 |
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 58 |
}
|
| 59 |
|
| 60 |
+
// Send user message and get AI response
|
| 61 |
async function sendMessage() {
|
| 62 |
const userText = input.value.trim();
|
| 63 |
if (!userText) return;
|
|
|
|
| 84 |
});
|
| 85 |
</script>
|
| 86 |
</body>
|
| 87 |
+
</html>
|