st-server / st-free /login.html
Qilan2's picture
Create login.html
3db99dc verified
<!DOCTYPE html>
<html>
<head>
<base href="/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-content">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="darkreader-lock">
<meta name="robots" content="noindex, nofollow" />
<style>
/* Put critical CSS here. The rest should go in stylesheets. */
body {
background-color: rgb(36, 36, 37);
}
/* 嵌入login.css */
body.login #shadow_popup {
opacity: 1;
display: flex;
}
body.login {
background-color: rgb(36, 36, 37);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
position: relative;
}
/* 添加半透明黑色遮罩提高文本可读性 */
body.login::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 0;
pointer-events: none;
}
/* 确保登录窗口在遮罩层上方 */
body.login #shadow_popup {
position: relative;
z-index: 1;
}
body.login .logo {
max-width: 30px;
}
body.login #logoBlock {
align-items: center;
margin: 0 auto;
gap: 10px;
}
body.login .userSelect {
display: flex;
flex-direction: column;
color: var(--SmartThemeBodyColor);
border: 1px solid var(--SmartThemeBorderColor);
border-radius: 5px;
padding: 3px 5px;
width: 30%;
cursor: pointer;
margin: 5px 0;
transition: background-color 0.15s ease-in-out;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
overflow: hidden;
}
body.login .userSelect .userName,
body.login .userSelect .userHandle {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
body.login .userSelect:hover {
background-color: var(--black30a);
}
body.login #handleEntryBlock,
body.login #passwordEntryBlock,
body.login #passwordRecoveryBlock {
margin: 2px;
}
/* 友联区样式 */
#friend-links-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(25, 25, 25, 0.95);
box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.5);
padding: 8px 0;
z-index: 9999;
text-align: center;
width: 100%;
}
.friend-links-title {
color: #ddd;
font-size: 14px;
margin-bottom: 5px;
font-weight: bold;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.friend-links-container {
display: flex;
overflow-x: auto;
white-space: nowrap;
padding: 0 15px;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE 和 Edge */
justify-content: center;
}
.friend-links-container::-webkit-scrollbar {
display: none; /* Chrome, Safari 和 Opera */
}
.friend-link {
display: inline-block;
margin: 0 8px;
padding: 5px 15px;
background-color: rgba(50, 50, 50, 0.7);
color: #fff;
text-decoration: none;
border-radius: 20px;
font-size: 13px;
transition: all 0.2s ease;
flex-shrink: 0;
}
.friend-link:hover {
background-color: rgba(70, 70, 70, 0.9);
transform: translateY(-2px);
}
.mobile-hint {
font-size: 10px;
color: rgba(200, 200, 200, 0.5);
margin-top: 5px;
font-style: italic;
}
/* 确保页面底部有足够空间不被友联遮挡 */
body.login {
padding-bottom: 80px;
}
/* 公告滚动区域样式 */
.announcement-container {
width: 100%;
overflow: hidden;
margin: 8px 0;
position: relative;
border-radius: 4px;
background-color: rgba(50, 50, 50, 0.4);
padding: 6px 0;
}
.announcement-container marquee {
color: #ff3333;
font-size: 14px;
padding: 0 5px;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 0.5px;
text-shadow: 0 0 2px rgba(255, 0, 0, 0.3);
}
@keyframes scroll-announcement {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}
/* 暂停滚动当鼠标悬停 - 由marquee的onmouseover属性处理 */
/* 移动设备适配 */
@media (max-width: 768px) {
.friend-links-container {
justify-content: flex-start;
padding: 0 10px;
}
.friend-link {
margin: 0 5px;
padding: 4px 10px;
font-size: 12px;
}
.friend-links-title {
font-size: 12px;
margin-bottom: 3px;
}
#friend-links-bar {
padding: 5px 0;
}
body.login {
padding-bottom: 70px;
}
}
/* 小屏幕设备适配 */
@media (max-width: 480px) {
.friend-link {
margin: 0 3px;
padding: 3px 8px;
font-size: 11px;
}
.mobile-hint {
font-size: 9px;
}
}
</style>
<link rel="preload" as="style" href="style.css">
<link rel="apple-touch-icon" sizes="57x57" href="img/apple-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="img/apple-icon-144x144.png" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="css/st-tailwind.css">
<!-- 移除 login.css 的引用,因为它已经内联到页面中 -->
<link rel="manifest" crossorigin="use-credentials" href="manifest.json">
<link href="webfonts/NotoSans/stylesheet.css" rel="stylesheet">
<link href="webfonts/NotoSansMono/stylesheet.css" rel="stylesheet">
<!-- fontawesome webfonts-->
<link href="css/fontawesome.min.css" rel="stylesheet">
<link href="css/solid.min.css" rel="stylesheet">
<link href="css/user.css" rel="stylesheet">
<title>[柒蓝-公益]云酒馆9号</title>
</head>
<body class="login">
<div id="shadow_popup" style="opacity: 0;">
<div id="dialogue_popup">
<div id="dialogue_popup_holder">
<div id="dialogue_popup_text">
<div id="userSelectBlock" class="flex-container flexFlowColumn alignItemsCenter">
<h2 id="logoBlock" class="flex-container">
<img src="img/logo.png" alt="SillyTavern" class="logo">
<span>[柒蓝-公益]云酒馆9号</span>
</h2>
<div class="announcement-container">
<marquee id="announcementText" scrollamount="4" behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
本云酒馆由谷歌colab机子搭建时间到期会换机子接力运行| 请注意接力-时间段 | 防止过载最多支持200个用户注册 | 且用且珍惜吧
</marquee>
</div>
<div id="userListBlock" class="wide100p">
<div id="userList" class="flex-container justifySpaceEvenly"></div>
<div id="handleEntryBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
<input id="userHandle" class="text_pole" type="text" placeholder="QQ" autocomplete="username" >
</div>
<div id="passwordEntryBlock" style="display:none;"
class="flex-container flexFlowColumn alignItemsCenter">
<input id="userPassword" class="text_pole" type="password" placeholder="密码" autocomplete="current-password">
<a id="recoverPassword" href="#" onclick="return false;">忘记密码请联系管理员</a>
<div class="flex-container">
<div id="loginButton" class="menu_button" style="white-space: nowrap;">登录</div>
</div>
</div>
<div id="passwordRecoveryBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
<div id="recoverMessage">
Recovery code has been posted to the server console.
</div>
<input id="recoveryCode" class="text_pole" type="text" placeholder="Recovery code">
<input id="newPassword" class="text_pole" type="password" placeholder="New password" autocomplete="new-password">
<div class="flex-container flexGap10">
<div id="sendRecovery" class="menu_button">Send</div>
<div id="cancelRecovery" class="menu_button">Cancel</div>
</div>
</div>
<div id="registerBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
<input id="registerHandle" class="text_pole" type="text" placeholder="QQ" autocomplete="username">
<input id="registerPassword" class="text_pole" type="password" placeholder="密码" autocomplete="new-password">
<input id="registerConfirm" class="text_pole" type="password" placeholder="确认密码" autocomplete="new-password">
<div class="flex-container">
<div id="registerButton" class="menu_button" style="white-space: nowrap;">注册</div>
<div id="backToLogin" class="menu_button" style="white-space: nowrap;">返回登录</div>
</div>
</div>
<div class="flex-container justifySpaceEvenly" style="white-space: nowrap;">
<div id="showRegister" class="menu_button">注册账号</div>
</div>
<div id="serverUptime" style="color: #888; font-size: 13px; margin-top: 10px; text-align: center;">
</div>
</div>
<div class="neutral_warning" id="errorMessage">
</div>
<div id="userCount" class="neutral_warning" style="color: #888; font-size: 12px; margin-top: 5px; text-align: center;">
</div>
<div>
接力时间[2025-08-09 11:45:54]
</div>
<div>
IP[35.185.53.73] 国家[美国] IPS[XX]
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 友联导航区 - 页面底部固定位置 -->
<div id="friend-links-bar">
<div class="friend-links-title">所有公益酒馆</div>
<div class="friend-links-container">
<a href="http://st.ql66.ggff.net:7070" class="friend-link">1号酒馆</a>
<a href="http://st.ql66.ggff.net:7073" class="friend-link">2号酒馆</a>
<a href="https://ka.282820.xyz/" class="friend-link">角色卡分享</a>
<a href="http://st.ql66.ggff.net:7076" class="friend-link">3号酒馆</a>
<a href="http://st.ql66.ggff.net:7078" class="friend-link">4号酒馆</a>
<a href="http://st.ql66.ggff.net:7080" class="friend-link">5号酒馆</a>
<a href="http://st.ql66.ggff.net:7082" class="friend-link">6号酒馆</a>
<a href="http://st.ql66.ggff.net:7084" class="friend-link">7号酒馆</a>
<!-- <a href="#" class="friend-link">7号酒馆</a>
<a href="#" class="friend-link">8号酒馆</a> -->
</div>
<div class="mobile-hint">← 左右滑动查看更多 →</div>
</div>
<script src="lib/jquery-3.5.1.min.js"></script>
<!-- 嵌入login2.js -->
<script>
/**
* CRSF token for requests.
*/
let csrfToken = '';
let discreetLogin = false;
/**
* Gets a CSRF token from the server.
* @returns {Promise<string>} CSRF token
*/
async function getCsrfToken() {
const response = await fetch('/csrf-token');
const data = await response.json();
return data.token;
}
/**
* Gets a list of users from the server.
* @returns {Promise<object>} List of users
*/
async function getUserList() {
const response = await fetch('/api/users/list', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
});
if (!response.ok) {
const errorData = await response.json();
return displayError(errorData.error || '发生错误');
}
if (response.status === 204) {
discreetLogin = true;
return [];
}
const userListObj = await response.json();
console.log(userListObj);
return userListObj;
}
/**
* Requests a recovery code for the user.
* @param {string} handle User handle
* @returns {Promise<void>}
*/
async function sendRecoveryPart1(handle) {
const response = await fetch('/api/users/recover-step1', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
body: JSON.stringify({ handle }),
});
if (!response.ok) {
const errorData = await response.json();
return displayError(errorData.error || '发生错误');
}
showRecoveryBlock();
}
/**
* Sets a new password for the user using the recovery code.
* @param {string} handle User handle
* @param {string} code Recovery code
* @param {string} newPassword New password
* @returns {Promise<void>}
*/
async function sendRecoveryPart2(handle, code, newPassword) {
const recoveryData = {
handle,
code,
newPassword,
};
const response = await fetch('/api/users/recover-step2', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
body: JSON.stringify(recoveryData),
});
if (!response.ok) {
const errorData = await response.json();
return displayError(errorData.error || '发生错误');
}
console.log(`密码恢复成功: ${handle}!`);
await performLogin(handle, newPassword);
}
/**
* Attempts to log in the user.
* @param {string} handle User's handle
* @param {string} password User's password
* @returns {Promise<void>}
*/
async function performLogin(handle, password) {
const userInfo = {
handle: handle,
password: password,
};
try {
const response = await fetch('/api/users/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
body: JSON.stringify(userInfo),
});
if (!response.ok) {
const errorData = await response.json();
return displayError(errorData.error || '发生错误');
}
const data = await response.json();
if (data.handle) {
console.log(`登录成功: ${handle}!`);
redirectToHome();
}
} catch (error) {
console.error('登录失败:', error);
displayError(String(error));
}
}
/**
* 处理用户注册
* @param {string} handle 用户QQ号
* @param {string} password 密码
* @param {string} confirmPassword 确认密码
* @returns {Promise<void>}
*/
async function performRegister(handle, password, confirmPassword) {
if (!handle) {
return displayError('QQ号不能为空');
}
// 验证用户名格式:只能是数字,长度6-13位
if (!/^\d{6,13}$/.test(handle)) {
return displayError('用户名只能是6-13位的数字');
}
if (!password) {
return displayError('密码不能为空');
}
if (password !== confirmPassword) {
return displayError('两次输入的密码不一致');
}
// 检查当前用户数量
try {
const countResponse = await fetch('/api/users-internal/count', {
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
}
});
if (countResponse.ok) {
const countData = await countResponse.json();
if (countData.totalCount >= 200) {
return displayError('系统已达到最大用户数限制(200),暂停注册');
}
}
} catch (error) {
console.error('检查用户数量失败:', error);
// 继续注册流程,因为这只是一个预检查
}
const userInfo = {
handle: handle,
name: handle, // 使用handle作为name
password: password
};
try {
const response = await fetch('/api/users-internal/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
},
body: JSON.stringify(userInfo)
});
if (!response.ok) {
const errorData = await response.json();
return displayError(errorData.error || '注册失败');
}
const data = await response.json();
if (data.handle) {
console.log(`注册成功: ${handle}!`);
// 注册成功后自动登录
await performLogin(handle, password);
}
} catch (error) {
console.error('注册失败:', error);
displayError(String(error));
}
}
/**
* Handles the user selection event.
* @param {object} user User object
* @returns {Promise<void>}
*/
async function onUserSelected(user) {
// No password, just log in
if (!user.password) {
return await performLogin(user.handle, '');
}
$('#passwordRecoveryBlock').hide();
$('#passwordEntryBlock').show();
$('#loginButton').off('click').on('click', async () => {
const password = String($('#userPassword').val());
await performLogin(user.handle, password);
});
$('#recoverPassword').off('click').on('click', async () => {
await sendRecoveryPart1(user.handle);
});
$('#sendRecovery').off('click').on('click', async () => {
const code = String($('#recoveryCode').val());
const newPassword = String($('#newPassword').val());
await sendRecoveryPart2(user.handle, code, newPassword);
});
displayError('');
}
/**
* Displays an error message to the user.
* @param {string} message Error message
*/
function displayError(message) {
$('#errorMessage').text(message);
}
/**
* Redirects the user to the home page.
* Preserves the query string.
*/
function redirectToHome() {
// After a login theres no need to preserve the
// noauto (if present)
const urlParams = new URLSearchParams(window.location.search);
urlParams.delete('noauto');
window.location.href = '/' + urlParams.toString();
}
/**
* Hides the password entry block and shows the password recovery block.
*/
function showRecoveryBlock() {
$('#passwordEntryBlock').hide();
$('#passwordRecoveryBlock').show();
displayError('');
}
/**
* Hides the password recovery block and shows the password entry block.
*/
function onCancelRecoveryClick() {
$('#passwordRecoveryBlock').hide();
$('#passwordEntryBlock').show();
displayError('');
}
/**
* 显示注册表单
*/
async function showRegisterForm() {
// 检查用户数量,如果已达到500用户,则显示错误信息而不显示注册表单
try {
const countResponse = await fetch('/api/users-internal/count', {
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
}
});
if (countResponse.ok) {
const countData = await countResponse.json();
if (countData.totalCount >= 200) {
return displayError('系统已达到最大用户数限制(200),暂停注册');
}
}
} catch (error) {
console.error('检查用户数量失败:', error);
// 继续显示注册表单,因为这只是一个预检查
}
$('#registerBlock').show();
$('#userListBlock > div:not(#registerBlock)').hide();
displayError('');
}
/**
* 返回登录页面
*/
function backToLoginForm() {
$('#registerBlock').hide();
if (discreetLogin) {
configureDiscreetLogin();
} else {
$('#userList').show();
$('#handleEntryBlock').hide();
$('#passwordEntryBlock').hide();
}
displayError('');
}
/**
* Configures the login page for normal login.
* @param {import('../../src/users').UserViewModel[]} userList List of users
*/
function configureNormalLogin(userList) {
console.log('Discreet login is disabled');
$('#handleEntryBlock').hide();
$('#normalLoginPrompt').show();
$('#discreetLoginPrompt').hide();
$('#registerBlock').hide();
console.log(userList);
for (const user of userList) {
const userBlock = $('<div></div>').addClass('userSelect');
const avatarBlock = $('<div></div>').addClass('avatar');
avatarBlock.append($('<img>').attr('src', user.avatar || 'img/default-avatar.png'));
userBlock.append(avatarBlock);
userBlock.append($('<span></span>').addClass('userName').text(user.name));
userBlock.append($('<small></small>').addClass('userHandle').text(user.handle));
userBlock.on('click', () => onUserSelected(user));
$('#userList').append(userBlock);
}
}
/**
* Configures the login page for discreet login.
*/
function configureDiscreetLogin() {
console.log('Discreet login is enabled');
$('#handleEntryBlock').show();
$('#normalLoginPrompt').hide();
$('#discreetLoginPrompt').show();
$('#userList').hide();
$('#passwordRecoveryBlock').hide();
$('#passwordEntryBlock').show();
$('#registerBlock').hide();
$('#loginButton').off('click').on('click', async () => {
const handle = String($('#userHandle').val());
const password = String($('#userPassword').val());
await performLogin(handle, password);
});
$('#recoverPassword').off('click').on('click', async () => {
const handle = String($('#userHandle').val());
await sendRecoveryPart1(handle);
});
$('#sendRecovery').off('click').on('click', async () => {
const handle = String($('#userHandle').val());
const code = String($('#recoveryCode').val());
const newPassword = String($('#newPassword').val());
await sendRecoveryPart2(handle, code, newPassword);
});
}
/**
* 初始化友联滑动功能
*/
function initFriendLinks() {
try {
const container = document.querySelector('.friend-links-container');
if (!container) {
console.log('友联容器未找到');
return;
}
// 检测是否为移动设备
const isMobile = window.innerWidth <= 768;
// 如果不是移动设备,触发一次自动滚动以显示所有链接
if (!isMobile && container.scrollWidth > container.clientWidth) {
let scrollPos = 0;
const maxScroll = container.scrollWidth - container.clientWidth;
const scrollInterval = setInterval(() => {
scrollPos += 1;
container.scrollLeft = scrollPos;
if (scrollPos >= maxScroll) {
clearInterval(scrollInterval);
setTimeout(() => {
container.scrollTo({
left: 0,
behavior: 'smooth'
});
}, 500);
}
}, 15);
// 最多滚动3秒
setTimeout(() => {
clearInterval(scrollInterval);
}, 3000);
}
console.log('友联滑动功能初始化完成');
} catch (error) {
console.error('初始化友联滑动功能时出错:', error);
}
}
// 初始化函数
(async function () {
csrfToken = await getCsrfToken();
const userList = await getUserList();
if (discreetLogin) {
configureDiscreetLogin();
} else {
configureNormalLogin(userList);
}
// 显示页面
document.getElementById('shadow_popup').style.opacity = '';
// 绑定事件处理函数
$('#cancelRecovery').on('click', onCancelRecoveryClick);
$('#showRegister').on('click', async () => {
await showRegisterForm();
});
$('#backToLogin').on('click', backToLoginForm);
// 注册按钮点击事件
$('#registerButton').on('click', async () => {
const handle = String($('#registerHandle').val());
const password = String($('#registerPassword').val());
const confirmPassword = String($('#registerConfirm').val());
await performRegister(handle, password, confirmPassword);
});
// 键盘事件处理
$(document).on('keydown', (evt) => {
if (evt.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
if ($('#passwordRecoveryBlock').is(':visible')) {
$('#sendRecovery').trigger('click');
} else if ($('#registerBlock').is(':visible')) {
$('#registerButton').trigger('click');
} else {
$('#loginButton').trigger('click');
}
}
});
// 查询总用户数量
try {
// console.log('正在获取用户总数...');
// 使用专门的API获取用户总数
const countResponse = await fetch('/api/users-internal/count', {
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
}
});
// console.log('用户总数API响应状态:', countResponse.status);
// 确保DOM元素存在
const userCountElement = document.getElementById('userCount');
if (countResponse.ok) {
// API成功
const countData = await countResponse.json();
// console.log('获取到的用户总数数据:', countData);
const totalUsers = countData.totalCount;
// console.log('总用户数:', totalUsers);
if (userCountElement) {
// 显示用户统计信息
userCountElement.textContent = `总用户数: ${totalUsers}/200`;
// 如果用户数量接近上限,添加警告样式
if (totalUsers >= 450) {
userCountElement.style.color = '#FF3333';
userCountElement.style.fontWeight = 'bold';
// 如果已达到500用户,隐藏注册按钮
if (totalUsers >= 200) {
$('#showRegister').hide();
displayError('已达到最大用户数限制(200),暂停注册');
}
}
// console.log('已更新用户数量显示');
} else {
console.error('找不到 userCount 元素');
}
} else {
console.warn('用户总数API访问受限,显示错误信息');
if (userCountElement) {
userCountElement.textContent = '无法获取用户总数';
}
}
} catch (error) {
console.error('获取用户数量失败:', error);
const userCountElement = document.getElementById('userCount');
if (userCountElement) {
userCountElement.textContent = '获取用户数量失败';
}
}
// 初始化友联滑动功能
initFriendLinks();
})();
// 确保DOM完全加载后初始化友联滑动功能
document.addEventListener('DOMContentLoaded', function() {
setTimeout(initFriendLinks, 1000);
});
</script>
<script>
/**
* 登录页面背景图片加载
*/
document.addEventListener('DOMContentLoaded', function() {
// 已知存在的背景图片 - 从实际文件夹中找到的
const bgImages = [
'img/bg/1.jpg',
'img/bg/2.jpg',
'img/bg/3.jpg',
'img/bg/4.jpg',
'img/bg/5.jpg',
'img/bg/6.jpg',
'img/bg/7.jpg',
'img/bg/8.jpg',
'img/bg/9.jpg',
'img/bg/10.jpg',
'img/bg/11.jpg',
'img/bg/12.jpg',
'img/bg/13.jpg',
'img/bg/14.jpg',
'img/bg/15.jpg',
'img/bg/16.jpg',
'img/bg/17.jpg',
'img/bg/18.jpg'
];
/**
* 设置随机背景图片
*/
function setRandomBackground() {
if (bgImages.length === 0) return;
// 随机选择一张图片
const randomIndex = Math.floor(Math.random() * bgImages.length);
const selectedImage = bgImages[randomIndex];
// 加载图片并设置为背景
const img = new Image();
img.onload = function() {
document.body.style.backgroundImage = `url('${selectedImage}')`;
console.log(`背景图片已设置: ${selectedImage}`);
};
img.onerror = function() {
console.warn(`背景图片加载失败: ${selectedImage}`);
// 从列表中移除无效图片
bgImages.splice(randomIndex, 1);
if (bgImages.length > 0) {
// 尝试下一张图片
setRandomBackground();
} else {
console.error('所有背景图片加载失败');
document.body.style.backgroundImage = 'none';
}
};
img.src = selectedImage;
}
// 调用函数设置随机背景
setRandomBackground();
});
</script>
</body>
</html>