尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

油猴脚本-自动刷新网页

油猴脚本-自动刷新网页
📅 发布时间:2026/6/20 16:00:40
// ==UserScript==
// @name         Userscript_reload
// @namespace    http://tampermonkey.net/
// @version      2025-09-29
// @description  每x分钟自动刷新当前页面,可手动暂停/继续,支持窗口拖动
// @author       You
// @match        https://www.baidu.com/*
// @grant        none
// ==/UserScript==(function() {'use strict';// 刷新间隔:x分钟 +(1--10)随机秒const REFRESH_INTERVAL =(5*60+Math.floor(Math.random() * 11))*1000;let timer = null;let remainingTime = REFRESH_INTERVAL;let isRunning = true;let isDragging = false;let offsetX, offsetY;// 创建控制界面function createControlPanel() {const panel = document.createElement('div');panel.id = 'autoRefreshPanel';panel.style.position = 'fixed';panel.style.bottom = '20px';panel.style.right = '20px';panel.style.backgroundColor = 'rgba(0,0,0,0.7)';panel.style.color = 'white';panel.style.padding = '10px 15px';panel.style.borderRadius = '5px';panel.style.zIndex = '999999';panel.style.fontFamily = 'Arial, sans-serif';panel.style.fontSize = '14px';panel.style.cursor = 'move'; // 提示可拖动// 添加标题栏(可拖动区域)const header = document.createElement('div');header.style.marginBottom = '8px';header.style.fontWeight = 'bold';header.style.userSelect = 'none'; // 防止拖动时选中文本header.textContent = '自动刷新控制';// 状态显示const statusDiv = document.createElement('div');statusDiv.id = 'autoRefreshStatus';statusDiv.textContent = `自动刷新: 启用 (剩余: ${formatTime(remainingTime)})`;statusDiv.style.marginBottom = '8px';statusDiv.style.cursor = 'default'; // 状态区恢复默认光标// 控制按钮const toggleBtn = document.createElement('button');toggleBtn.textContent = '暂停';toggleBtn.style.marginLeft = '10px';toggleBtn.style.padding = '3px 8px';toggleBtn.style.cursor = 'pointer';toggleBtn.style.border = 'none';toggleBtn.style.borderRadius = '3px';toggleBtn.style.backgroundColor = '#ff4444';toggleBtn.style.color = 'white';toggleBtn.style.cursor = 'default'; // 按钮恢复默认光标toggleBtn.addEventListener('click', toggleRefresh);// 组装面板panel.appendChild(header);panel.appendChild(statusDiv);panel.appendChild(toggleBtn);document.body.appendChild(panel);// 添加拖动事件监听addDragEvents(panel);}// 添加拖动功能function addDragEvents(element) {// 鼠标按下时开始拖动element.addEventListener('mousedown', (e) => {// 只有点击标题栏才允许拖动if (e.target === element || e.target === element.firstChild) {isDragging = true;// 计算鼠标相对于面板的位置const rect = element.getBoundingClientRect();offsetX = e.clientX - rect.left;offsetY = e.clientY - rect.top;element.style.transition = 'none'; // 关闭动画使拖动更流畅}});// 鼠标移动时更新面板位置document.addEventListener('mousemove', (e) => {if (!isDragging) return;const panel = document.getElementById('autoRefreshPanel');// 计算新位置(确保面板不会超出视口)const newX = e.clientX - offsetX;const newY = e.clientY - offsetY;// 限制在窗口内const maxX = window.innerWidth - panel.offsetWidth;const maxY = window.innerHeight - panel.offsetHeight;const constrainedX = Math.max(0, Math.min(newX, maxX));const constrainedY = Math.max(0, Math.min(newY, maxY));// 设置新位置panel.style.left = `${constrainedX}px`;panel.style.top = `${constrainedY}px`;// 清除原来的bottom和right属性,改用left和toppanel.style.bottom = 'auto';panel.style.right = 'auto';});// 鼠标释放时停止拖动document.addEventListener('mouseup', () => {if (isDragging) {isDragging = false;const panel = document.getElementById('autoRefreshPanel');panel.style.transition = 'all 0.1s ease'; // 恢复轻微动画}});// 鼠标离开窗口时停止拖动document.addEventListener('mouseleave', () => {isDragging = false;const panel = document.getElementById('autoRefreshPanel');panel.style.transition = 'all 0.1s ease';});}// 格式化时间显示 (毫秒 -> 分:秒)function formatTime(ms) {const totalSeconds = Math.floor(ms / 1000);const minutes = Math.floor(totalSeconds / 60);const seconds = totalSeconds % 60;return `${minutes}:${seconds.toString().padStart(2, '0')}`;}// 更新倒计时显示function updateDisplay() {const statusDiv = document.getElementById('autoRefreshStatus');if (statusDiv) {statusDiv.textContent = `自动刷新: ${isRunning ? '启用' : '暂停'} (剩余: ${formatTime(remainingTime)})`;}}// 切换刷新状态 (暂停/继续)function toggleRefresh() {isRunning = !isRunning;const btn = document.querySelector('#autoRefreshPanel button');if (isRunning) {btn.textContent = '暂停';btn.style.backgroundColor = '#ff4444';startTimer();} else {btn.textContent = '继续';btn.style.backgroundColor = '#00C851';clearInterval(timer);}updateDisplay();}// 开始倒计时function startTimer() {clearInterval(timer);timer = setInterval(() => {if (isRunning) {remainingTime -= 1000;updateDisplay();if (remainingTime <= 0) {// 刷新页面location.reload();}}}, 1000);}// 初始化createControlPanel();startTimer();// 页面卸载时清除定时器window.addEventListener('beforeunload', () => {clearInterval(timer);});
})();

  

相关新闻

  • PostgreSQL数据库查询表是否被锁,以及解锁表的办法
  • 用信号量机制实现互斥,同步,前驱
  • AxC杂题乱做

最新新闻

  • 2026年上海梅雨季旧房翻新全攻略:防潮防霉与靠谱机构推荐 - 优家闲谈
  • 构建实时语音转写系统:TMSpeech技术架构与应用实践
  • 2026在无锡回收首饰不玩虚高引流,线上预估价≈线下成交价,所有收费提前说明 - 讯息早知道
  • 如何快速掌握Nintendo Switch游戏备份:NxDumpTool终极指南
  • 2026无锡钻石回收TOP榜首|翘楚领衔,高溢价透明变现首选 - 讯息早知道
  • 2026深圳今日金价高位运行逸程实测教你卖金不亏 - 逸程

日新闻

  • 信任的进化:技术实现详解——如何用JavaScript构建博弈论模拟器
  • Terrakube自定义工作流:如何集成OPA、Infracost等工具扩展IaC能力
  • grunt-concurrent快速入门:5分钟学会并行运行Grunt任务

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号