html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>智能搜索主页</title>
<style>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html, body {
height: 100%;
font-family: 'Segoe UI', sans-serif;
color: white;
}
body {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.overlay {
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
z-index: 0;
}
.container {
position: relative;
z-index: 2;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
padding: 20px;
}
.search-box {
display: flex;
flex-direction: column;
gap: 15px;
width: 100%;
max-width: 600px;
align-items: center;
}
input[type="text"] {
width: 100%;
padding: 15px;
font-size: 18px;
border: none;
border-radius: 25px;
outline: none;
}
select, button {
padding: 8px 16px;
font-size: 16px;
border-radius: 20px;
border: none;
background-color: rgba(255,255,255,0.2);
color: white;
backdrop-filter: blur(5px);
cursor: pointer;
}
select {
background-color: rgba(255,255,255,0.3);
}
button:hover {
background-color: rgba(255,255,255,0.3);
}
.footer {
position: absolute;
bottom: 10px;
width: 100%;
text-align: center;
font-size: 14px;
opacity: 0.7;
}
</style>
</head>
<body>
<div class="overlay"></div>
<div class="container">
<div class="search-box">
<h1>🧭 智能搜索主页</h1>
<input type="text" id="searchInput" placeholder="输入网址或搜索内容..." />
<div style="display: flex; gap: 10px;">
<select id="engineSelect">
<option value="https://www.google.com/search?q=" selected>Google</option>
<option value="https://www.bing.com/search?q=">Bing</option>
<option value="https://www.baidu.com/s?wd=">百度</option>
<option value="https://duckduckgo.com/?q=">DuckDuckGo</option>
</select>
<button onclick="handleSearch()">搜索</button>
</div>
</div>
</div>
<div class="footer">
每日背景来自 Bing | ChatGPT 生成 @ 2025
</div>
<script>
function isURL(str) {
const pattern = /^https?:\/\/|www\.|(\.\w{2,})/i;
return pattern.test(str);
}
function handleSearch() {
const input = document.getElementById("searchInput").value.trim();
const engine = document.getElementById("engineSelect").value;
if (!input) return;
if (isURL(input)) {
// 加前缀跳转访问链接
let url = input;
if (!/^https?:\/\//i.test(url)) {
url = "https://" + url;
}
window.location.href = url;
} else {
// 使用搜索引擎查询
const queryUrl = engine + encodeURIComponent(input);
window.location.href = queryUrl;
}
}
// 回车键触发搜索
document.getElementById("searchInput").addEventListener("keydown", function(e) {
if (e.key === "Enter") handleSearch();
});
// 设置每日 Bing 背景图片
async function setBingBackground() {
try {
const response = await fetch('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
const data = await response.json();
const imageUrl = "https://www.bing.com" + data.images[0].url;
document.body.style.backgroundImage = `url(${imageUrl})`;
} catch (error) {
console.error("背景图加载失败,使用默认颜色");
document.body.style.backgroundColor = "#333";
}
}
setBingBackground();
</script>
</body>
</html>