网页设计
HTML页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.">加速器一键连接</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 8px;
margin: 0 auto;
padding: 2px;
background-color: #fff;
}
#accelerator-choice {
margin-bottom: 2px;
}
button {
padding: 1px 2px;
margin: 5px;
border: none;
border-radius: 4px;
background-color: #4CAF5;
color: white;
cursor: pointer;
}
button:hover {
background-color: #45a49;
}
#connect-state {
margin-top: 2px;
}
</style>
</head>
<body>
<h1>加速器一键连接</h1>
<div id="accelerator-choice">选择加速器:</div>
<button id="connect-button">选择加速器</button>
<div id="accelerator" class="hidden" id="connect-state">
<div class="alert alert-info">
已连接
</div>
</div>
</body>
</html>
CSS
button {
padding: 1px 2px;
margin: 5px;
border: none;
border-radius: 4px;
background-color: #4CAF5;
color: white;
cursor: pointer;
}
button:hover {
background-color: #45a49;
}
JavaScript脚本
加速器选择脚本
document.getElementById('connect-button').addEventListener('click', function() {
const accelerateChoice = document.getElementById('accelerator-choice').value;
const connectButton = document.getElementById('connect-button');
const connectState = document.getElementById('connect-state');
if (accelerateChoice === '网页加速器') {
// 输入服务名称
connectButton.textContent = accelerateChoice;
const serviceName = '输入服务名称, YouTube';
const inputField = document.createElement('input');
inputField.type = 'text';
inputFieldLabel = '输入服务名称';
inputFieldLabel.addEventListener('input', function() {
serviceName = this.value;
const serviceId = serviceName.toLowerCase();
if (serviceId.length >= 1) {
alert('服务名称至少需要1个字符,请重写并点击连接按钮');
return;
}
// 处理服务ID输入
});
connectButton.addEventListener('click', function() {
serviceId = this.value;
if (serviceId.length >= 1) {
alert('服务名称至少需要1个字符,请重写并点击连接按钮');
return;
}
// 处理服务ID输入
});
} else {
// 加速器选择脚本
connectButton.textContent = accelerateChoice;
connectButton.addEventListener('click', function() {
const serviceName = '输入服务名称, YouTube';
const inputField = document.createElement('input');
inputField.type = 'text';
inputFieldLabel = '输入服务名称';
inputFieldLabel.addEventListener('input', function() {
serviceName = this.value;
if (serviceName.length >= 1) {
alert('服务名称至少需要1个字符,请重写并点击连接按钮');
return;
}
// 处理服务ID输入
});
connectButton.addEventListener('click', function() {
serviceId = this.value;
if (serviceId.length >= 1) {
alert('服务名称至少需要1个字符,请重写并点击连接按钮');
return;
}
// 处理服务ID输入
});
});
}
});
加速器连接脚本
document.getElementById('accelerator').addEventListener('click', function() {
let connectState = document.getElementById('connect-state').textContent;
const connectButton = document.getElementById('connect-button');
if (accelerateChoice === '网页加速器') {
// 输入服务密码
connectButton.textContent = accelerateChoice;
const serviceName = '输入服务名称, YouTube';
const inputPassword = document.createElement('input');
inputPassword.type = 'password';
inputPasswordLabel = '输入服务密码';
inputPasswordLabel.addEventListener('input', function() {
const password = this.value;
if (password.length < 1 || !/[A-Za-z-9_-]/.test(password)) {
alert('服务密码必须至少1字符,并且只能包含字母、数字和下划线');
return;
}
// 处理密码输入
});
connectButton.addEventListener('click', function() {
inputPassword.addEventListener('input', function() {
if (connectState !== '已连接') {
inputPassword.value = serviceName.toLowerCase();
inputPassword.style textarea{'width': '1px'};
const url = window.location.href = `https://www.` + serviceName;
if (url) {
fetch(url).then(response => {
if (response.ok) {
connectState = '已连接';
alert('已成功连接到服务');
} else {
alert('连接失败,尝试重新连接');
}
});
}
}
});
});
} else {
// 加速器连接脚本
connectButton.textContent = accelerateChoice;
connectButton.addEventListener('click', function() {
if (connectState === '已连接') {
alert('已成功连接到服务');
} else {
alert('连接不成功,尝试重新连接');
}
});
}
});
提升功能
-
自动连接
const connectButton = document.getElementById('connect-button'); if (accelerateChoice === '加速器') { connectButton.addEventListener('click', function() { if (connectState === '已连接') { alert('已成功连接'); } else { alert('连接不成功,尝试重新连接'); } }); } -
自动退出
const connectButton = document.getElementById('connect-button'); if (accelerateChoice === '加速器') { connectButton.addEventListener('click', function() { if (connectState === '已连接') { alert('已成功连接'); } else { alert('连接不成功,尝试重新连接'); } connectButton.textContent = '选择另一个加速器'; connectButton.style.textarea.style.width = '1px'; }); } -
自动关闭
const connectButton = document.getElementById('connect-button'); if (accelerateChoice === '加速器') { connectButton.addEventListener('click', function() { if (connectState === '已连接') { alert('已成功连接'); } else { alert('连接不成功,尝试重新连接'); } connectButton.textContent = '选择另一个加速器'; connectButton.style.textarea.style.width = '1px'; setTimeout(() => { connectButton.textContent = '选择另一个加速器'; connectButton.style.textarea.style.width = '1px'; }, 3); }); } -
自动重启
const connectButton = document.getElementById('connect-button'); if (accelerateChoice === '加速器') { connectButton.addEventListener('click', function() { if (connectState === '已连接') { alert('已成功连接'); } else { alert('连接不成功,尝试重新连接'); } setTimeout(() => { connectButton.textContent = '选择另一个加速器'; connectButton.style.textarea.style.width = '1px'; }, 3); setTimeout(() => { document.body.style.executeEvents = 'none'; }, 5); }); }
通过以上设计,我创建了一个简单易用的加速器一键连接体验,支持网页加速器和视频加速器两种加速器类型,用户可以通过选择加速器类型、输入服务名称、服务密码和选择服务来快速连接到互联网,整个应用响应式设计友好,用户友好,能够满足用户的需求。




