简单的防休眠工具(web版)

发布时间: 2013-05-01 热度: 450

这是一个简单的防休眠工具,可以帮助防止您的电脑进入睡眠状态。以下是该工具的主要特点:

  1. 基本原理:工具通过定期模拟微小的鼠标移动来保持计算机活动状态
  2. 可自定义设置:
    • 可调整移动间隔时间(5-300秒)
    • 可调整移动距离(1-10像素)
  3. 实时状态显示:
    • 显示当前运行状态
    • 计数器显示已执行的活动次数
    • 活动日志记录详细信息

使用方法:

  1. 打开HTML文件
  2. 根据需要调整设置
  3. 点击"开始"按钮启动防休眠功能
  4. 需要时点击"停止"按钮关闭功能

这个工具完全在浏览器中运行,不需要安装任何额外的软件,只要保持网页打开即可生效。

您可以将此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>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f4f8;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 30px;
            text-align: center;
            max-width: 500px;
            width: 100%;
        }
        h1 {
            color: #2c3e50;
            margin-bottom: 20px;
        }
        .status {
            font-size: 18px;
            margin: 20px 0;
            color: #7f8c8d;
        }
        .active {
            color: #27ae60;
            font-weight: bold;
        }
        .inactive {
            color: #e74c3c;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 24px;
            font-size: 16px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin: 10px;
        }
        button:hover {
            background-color: #2980b9;
        }
        .stop {
            background-color: #e74c3c;
        }
        .stop:hover {
            background-color: #c0392b;
        }
        .settings {
            margin: 20px 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .settings label {
            margin: 10px 0;
            font-size: 14px;
            color: #34495e;
        }
        .counter {
            font-size: 14px;
            color: #7f8c8d;
            margin-top: 20px;
        }
        .activity-log {
            text-align: left;
            margin-top: 20px;
            padding: 10px;
            background-color: #f8f9fa;
            border-radius: 5px;
            max-height: 150px;
            overflow-y: auto;
            font-size: 12px;
            color: #666;
        }
        .activity-log p {
            margin: 3px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>防休眠工具</h1>
        <p>此工具通过定期模拟鼠标微小移动来防止电脑进入休眠状态。</p>
        
        <div class="settings">
            <label>
                移动间隔 (秒):
                <input type="number" id="interval" min="5" max="300" value="30">
            </label>
            <label>
                移动距离 (像素):
                <input type="number" id="distance" min="1" max="10" value="1">
            </label>
        </div>
        
        <div id="status" class="status inactive">状态: 未运行</div>
        
        <button id="startBtn">开始</button>
        <button id="stopBtn" class="stop" disabled>停止</button>
        
        <div id="counter" class="counter">活动次数: 0</div>
        
        <div class="activity-log" id="log">
            <p>日志记录将显示在这里...</p>
        </div>
    </div>

    <script>
        // 获取元素
        const statusEl = document.getElementById('status');
        const startBtn = document.getElementById('startBtn');
        const stopBtn = document.getElementById('stopBtn');
        const counterEl = document.getElementById('counter');
        const intervalInput = document.getElementById('interval');
        const distanceInput = document.getElementById('distance');
        const logEl = document.getElementById('log');
        
        // 变量初始化
        let isActive = false;
        let timerId = null;
        let moveCount = 0;
        let currentPosition = 1;
        
        // 添加日志记录
        function addLog(message) {
            const time = new Date().toLocaleTimeString();
            const logEntry = document.createElement('p');
            logEntry.textContent = `${time}: ${message}`;
            logEl.appendChild(logEntry);
            
            // 自动滚动到底部
            logEl.scrollTop = logEl.scrollHeight;
            
            // 限制日志条目数量
            if (logEl.children.length > 100) {
                logEl.removeChild(logEl.children[0]);
            }
        }
        
        // 模拟鼠标移动
        function simulateMouseMovement() {
            const distance = parseInt(distanceInput.value) || 1;
            
            // 创建并移动一个临时对象
            const tempEl = document.createElement('div');
            tempEl.style.position = 'fixed';
            tempEl.style.width = '1px';
            tempEl.style.height = '1px';
            tempEl.style.backgroundColor = 'transparent';
            tempEl.style.top = '0';
            tempEl.style.left = '0';
            tempEl.style.zIndex = '-1';
            document.body.appendChild(tempEl);
            
            // 交替移动方向
            currentPosition *= -1;
            tempEl.style.transform = `translate(${distance * currentPosition}px, ${distance * currentPosition}px)`;
            
            // 更新计数器
            moveCount++;
            counterEl.textContent = `活动次数: ${moveCount}`;
            
            // 记录日志
            addLog(`鼠标移动了 ${distance} 像素`);
            
            // 删除临时元素
            setTimeout(() => {
                document.body.removeChild(tempEl);
            }, 100);
        }
        
        // 开始防休眠
        function startPrevention() {
            if (isActive) return;
            
            const interval = Math.max(5, parseInt(intervalInput.value) || 30) * 1000;
            
            isActive = true;
            statusEl.className = 'status active';
            statusEl.textContent = '状态: 运行中';
            
            startBtn.disabled = true;
            stopBtn.disabled = false;
            
            // 立即执行一次
            simulateMouseMovement();
            
            // 设置定时器定期执行
            timerId = setInterval(simulateMouseMovement, interval);
            
            addLog(`防休眠已启动,间隔: ${interval/1000} 秒`);
        }
        
        // 停止防休眠
        function stopPrevention() {
            if (!isActive) return;
            
            isActive = false;
            statusEl.className = 'status inactive';
            statusEl.textContent = '状态: 未运行';
            
            startBtn.disabled = false;
            stopBtn.disabled = true;
            
            clearInterval(timerId);
            
            addLog('防休眠已停止');
        }
        
        // 事件监听器
        startBtn.addEventListener('click', startPrevention);
        stopBtn.addEventListener('click', stopPrevention);
        
        // 初始日志
        addLog('工具已准备就绪,点击"开始"按钮启动防休眠功能');
    </script>
</body>
</html>

在下方留下您的评论.加入TG群.打赏🍗