first commit

This commit is contained in:
2025-07-16 14:14:10 +08:00
commit 880de1dd78
3 changed files with 298 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voice Assistant</title>
<link rel="stylesheet" href="style.css">
<!-- 引入 Font Awesome 图标库,用于麦克风图标 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<!-- 视频背景 -->
<video autoplay muted loop id="bg-video">
<!-- 初始可以留空,或放一个默认视频 -->
<source id="video-source" src="" type="video/mp4">
Your browser does not support the video tag.
</video>
<!-- 内容层,覆盖在视频之上 -->
<div class="content-overlay">
<!-- 顶部好感度条 -->
<header class="top-bar">
<label for="favorability-bar">Favorability</label>
<div class="progress-container">
<div class="progress-fill" id="favorability-bar"></div>
</div>
</header>
<!-- 中间区域,用于放置上传按钮 -->
<main class="center-content">
<label for="video-upload" class="upload-button">Change Background</label>
<input type="file" id="video-upload" accept="video/*" hidden>
</main>
<!-- 底部麦克风和链接 -->
<footer class="bottom-bar">
<button class="mic-button" id="mic-button" aria-label="Start Listening">
<i class="fas fa-microphone"></i>
</button>
<a href="https://x.com/jackywine" target="_blank" rel="noopener noreferrer" class="footer-credit">
@jackywine
</a>
</footer>
</div>
<script src="script.js"></script>
</body>
</html>
+59
View File
@@ -0,0 +1,59 @@
document.addEventListener('DOMContentLoaded', function() {
// 获取需要的 DOM 元素
const videoUploadInput = document.getElementById('video-upload');
const bgVideo = document.getElementById('bg-video');
const videoSource = document.getElementById('video-source');
const micButton = document.getElementById('mic-button');
const favorabilityBar = document.getElementById('favorability-bar');
// --- 视频上传功能 ---
videoUploadInput.addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
// 使用 URL.createObjectURL 为用户选择的本地文件创建一个临时的 URL
const fileURL = URL.createObjectURL(file);
// 设置 video 元素的 source
videoSource.setAttribute('src', fileURL);
// 加载并播放新的视频
bgVideo.load();
bgVideo.play().catch(error => {
// 某些浏览器可能会阻止自动播放,这是一种友好的处理方式
console.error("Video play failed:", error);
});
}
});
// --- 麦克风按钮交互和好感度条模拟 ---
let isListening = false;
let currentFavorability = 65; // 与 CSS 中的初始宽度保持一致
micButton.addEventListener('click', function() {
isListening = !isListening;
// 切换 "监听中" 的样式 (动画)
micButton.classList.toggle('is-listening', isListening);
// 模拟交互:每次点击麦克风,好感度增加
if (isListening) {
// 增加好感度,但最高不超过 100
currentFavorability += 5;
if (currentFavorability > 100) {
currentFavorability = 100;
}
} else {
// 如果停止监听,可以稍微降低一点好感度(可选)
currentFavorability -= 2;
if (currentFavorability < 0) {
currentFavorability = 0;
}
}
// 更新好感度进度条的宽度
favorabilityBar.style.width = currentFavorability + '%';
});
});
+188
View File
@@ -0,0 +1,188 @@
/* --- 基本重置和全局样式 --- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
color: white;
overflow: hidden; /* 防止视频导致滚动条 */
}
/* --- 视频背景 --- */
#bg-video {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
transform: translateX(-50%) translateY(-50%);
z-index: -1; /* 将视频置于最底层 */
object-fit: cover; /* 关键:让视频填满整个屏幕而不变形 */
background-color: #1a1a1a; /* 视频加载前的背景色 */
}
/* --- 内容覆盖层 --- */
.content-overlay {
position: relative;
height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between; /* 顶部和底部分别对齐 */
align-items: center;
padding: 25px;
background-color: rgba(0, 0, 0, 0.35); /* 半透明黑色蒙版,确保文字清晰可见 */
z-index: 1;
}
/* --- 顶部好感度条 --- */
.top-bar {
width: 100%;
max-width: 500px;
text-align: left;
}
.top-bar label {
font-size: 1rem;
font-weight: 600;
text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
margin-bottom: 8px;
display: block;
}
.progress-container {
width: 100%;
height: 12px;
background-color: rgba(255, 255, 255, 0.3);
border-radius: 10px;
overflow: hidden;
}
.progress-fill {
height: 100%;
width: 65%; /* 初始好感度值 */
background: linear-gradient(90deg, #4facfe, #00f2fe);
border-radius: 10px;
transition: width 0.5s ease-in-out;
}
/* --- 中间内容 (上传按钮) --- */
.center-content {
/* 这个区域是弹性填充的,所以不需要太多样式 */
}
.upload-button {
background-color: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.5);
padding: 8px 16px;
border-radius: 20px;
cursor: pointer;
font-size: 0.9rem;
transition: background-color 0.3s ease;
}
.upload-button:hover {
background-color: rgba(255, 255, 255, 0.4);
}
/* --- 底部内容 --- */
.bottom-bar {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.mic-button {
width: 80px;
height: 80px;
background: linear-gradient(45deg, #ff5f6d, #ffc371);
border: none;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.mic-button:hover {
transform: scale(1.1);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.mic-button:active {
transform: scale(1.05);
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.mic-button i {
font-size: 36px;
color: white;
}
/* 麦克风 "监听中" 的动画效果 */
.mic-button.is-listening {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(255, 95, 109, 0.7);
}
70% {
box-shadow: 0 0 0 20px rgba(255, 95, 109, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(255, 95, 109, 0);
}
}
.footer-credit {
margin-top: 20px;
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
font-size: 1rem;
transition: color 0.3s ease;
}
.footer-credit:hover {
color: white;
text-decoration: underline;
}
/* --- 响应式设计 --- */
@media (max-width: 600px) {
.content-overlay {
padding: 20px;
}
.top-bar label {
font-size: 0.9rem;
}
.progress-container {
height: 10px;
}
.mic-button {
width: 70px;
height: 70px;
}
.mic-button i {
font-size: 30px;
}
.footer-credit {
margin-top: 15px;
font-size: 0.9rem;
}
}