Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<title>W5 PR 練習 Chatbot</title>
<title>D1257081 的 PR 練習 Chatbot</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="container">
<header>
<h1>🤖 PR 練習 Chatbot</h1>
<p class="subtitle">W5 Pull Request 練習</p>
<h1>💬 D1257081 的 Chatbot</h1>
<p class="subtitle">W5 Pull Request 練習 — by D1257081</p>
<input id="search-input" type="text" placeholder="搜尋訊息..." oninput="searchMessages(this.value)">
</header>

<div id="chat-box">
Expand All @@ -21,11 +22,24 @@ <h1>🤖 PR 練習 Chatbot</h1>

<div class="input-area">
<input id="user-input" type="text" placeholder="輸入訊息...">
<button onclick="sendMessage()">送出</button>
<button onclick="sendMessage()">發送訊息 💬</button>
</div>
</div>

<script>
function searchMessages(keyword) {
const messages = document.querySelectorAll('#chat-box .message');
const query = keyword.trim().toLowerCase();
messages.forEach(msg => {
const text = msg.textContent.toLowerCase();
if (!query || text.includes(query)) {
msg.classList.remove('hidden');
} else {
msg.classList.add('hidden');
}
});
}

function sendMessage() {
const input = document.getElementById('user-input');
const chatBox = document.getElementById('chat-box');
Expand All @@ -35,12 +49,20 @@ <h1>🤖 PR 練習 Chatbot</h1>

const userDiv = document.createElement('div');
userDiv.className = 'message user';
const timeUser = document.createElement('span');
timeUser.className = 'timestamp';
timeUser.textContent = new Date().toLocaleTimeString('zh-TW', {hour:'2-digit', minute:'2-digit'});
userDiv.textContent = text;
userDiv.appendChild(timeUser);
chatBox.appendChild(userDiv);

const botDiv = document.createElement('div');
botDiv.className = 'message bot';
const timeBot = document.createElement('span');
timeBot.className = 'timestamp';
timeBot.textContent = new Date().toLocaleTimeString('zh-TW', {hour:'2-digit', minute:'2-digit'});
botDiv.textContent = `你說了「${text}」!`;
botDiv.appendChild(timeBot);
chatBox.appendChild(botDiv);

input.value = '';
Expand Down
31 changes: 27 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body {
}

header {
background: #4f8ef7;
background: linear-gradient(135deg, #00b894, #00cec9);
color: white;
padding: 20px 24px;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ header .subtitle { font-size: 13px; opacity: 0.85; margin-top: 4px; }
}

.message.user {
background: #4f8ef7;
background: #00b894;
color: white;
align-self: flex-end;
}
Expand All @@ -74,10 +74,10 @@ header .subtitle { font-size: 13px; opacity: 0.85; margin-top: 4px; }
outline: none;
}

.input-area input:focus { border-color: #4f8ef7; }
.input-area input:focus { border-color: #00b894; }

.input-area button {
background: #4f8ef7;
background: #00b894;
color: white;
border: none;
padding: 10px 20px;
Expand All @@ -87,3 +87,26 @@ header .subtitle { font-size: 13px; opacity: 0.85; margin-top: 4px; }
}

.input-area button:hover { opacity: 0.85; }

/* feature/add-search 新增 */
header input {
margin-top: 8px;
width: 100%;
padding: 6px 10px;
border: none;
border-radius: 6px;
font-size: 13px;
background: rgba(255,255,255,0.25);
color: white;
}
header input::placeholder { color: rgba(255,255,255,0.7); }
.message.hidden { display: none; }

/* feature/add-timestamp 新增 */
.timestamp {
display: block;
font-size: 10px;
opacity: 0.6;
text-align: right;
margin-top: 4px;
}