// ==UserScript== // @name 自动滚动 // @namespace https://github.com/LaLa-HaHa-Hei/ // @version 1.0.0 // @description 不断向下或向上滚动页面,可自定义速度和方向。 // @author 代码见三 // @match *://*/* // @noframes // @grant GM_registerMenuCommand // ==/UserScript== (function () { 'use strict'; let scrollInterval = null; let isScrolling = false; // 默认配置 const config = { intervalTime: 50, // 滚动间隔(毫秒) scrollStep: 2, // 每次滚动步长(像素) direction: 1, // 1=向下, -1=向上 edgeMargin: 100 // 边缘余量(像素) }; // 开始自动滚动 function startAutoScroll() { if (scrollInterval) { clearInterval(scrollInterval); } isScrolling = true scrollInterval = setInterval(() => { const currentScroll = window.scrollY; const documentHeight = document.documentElement.scrollHeight; const windowHeight = window.innerHeight; // 检测是否到达底部或顶部 if (currentScroll + windowHeight >= documentHeight - config.edgeMargin) { config.direction = -1; // 到达底部改为向上 } else if (currentScroll <= config.edgeMargin) { config.direction = 1; // 到达顶部改为向下 } window.scrollBy(0, config.scrollStep * config.direction) }, config.intervalTime); // alert('自动滚动已开始!方向: ' + (config.direction === 1 ? '向下' : '向上')); } // 停止自动滚动 function stopAutoScroll() { if (scrollInterval) { clearInterval(scrollInterval); scrollInterval = null; isScrolling = false; // alert('自动滚动已停止'); } } // 切换滚动方向 function toggleDirection() { config.direction *= -1; // alert('滚动方向已切换为: ' + (config.direction === 1 ? '向下' : '向上')); if (isScrolling) { startAutoScroll(); // 重新开始以应用新方向 } } // 注册菜单命令 GM_registerMenuCommand("开始自动滚动", startAutoScroll, "s"); GM_registerMenuCommand("停止自动滚动", stopAutoScroll, "t"); GM_registerMenuCommand("切换滚动方向", toggleDirection, "d"); GM_registerMenuCommand("设置滚动速度", () => { const speed = prompt("请输入滚动速度(1-100,默认5):", "5"); if (speed && !isNaN(speed)) { config.intervalTime = Math.max(10, 110 - (speed * 10)); if (isScrolling) startAutoScroll(); alert(`速度已设置为 ${speed} (间隔时间: ${config.intervalTime}ms)`); } }, "v"); })();