滑动器2

控制网页自动向上滑动的速度

Pada tanggal 30 April 2023. Lihat %(latest_version_link).

// ==UserScript==
// @name         滑动器2
// @namespace    your-namespace
// @version      1.0
// @description  控制网页自动向上滑动的速度
// @author       Your Name
// @match        http://www.htmanga3.top/*
// @grant        none
// ==/UserScript==

// 按下音量减键时滚动网页
document.addEventListener('keydown', function(event) {
  if (event.code === 'Minus') { // 检查是否按下音量减键
    scrollPage(); // 滚动网页
  } else if (event.code === 'Equal') { // 检查是否按下音量加键
    stopScrolling(); // 停止滚动
  }
});

// 滚动网页函数
function scrollPage() {
  const scrollInterval = setInterval(function() {
    window.scrollBy(0, 10); // 向下滚动页面
  }, 10);
  
  // 记录滚动定时器ID以便后续停止滚动
  localStorage.setItem('scrollInterval', scrollInterval);
}

// 停止滚动函数
function stopScrolling() {
  const scrollInterval = localStorage.getItem('scrollInterval');
  clearInterval(scrollInterval); // 停止滚动
}

// 网页滑动1秒后停止1秒
let scrollTimer;
let stopTimer;

function startScroll() {
  scrollTimer = setInterval(function() {
    window.scrollBy(0, 10);
  }, 10);
  
  stopTimer = setTimeout(function() {
    clearInterval(scrollTimer);
  }, 1000);
}

// 弹窗用来修改滑动和停止时间
function showSettingsDialog() {
  const input = prompt('请输入滑动时间和停止时间,以逗号分隔(单位:毫秒)');
  if (input) {
    const times = input.split(',');
    clearInterval(scrollTimer);
    clearTimeout(stopTimer);
    scrollTimer = setInterval(function() {
      window.scrollBy(0, 10);
    }, Number(times[0]));
    stopTimer = setTimeout(function() {
      clearInterval(scrollTimer);
    }, Number(times[1]));
  }
}

// 按下音量减键弹出设置对话框
document.addEventListener('keydown', function(event) {
  if (event.code === 'Minus') {
    showSettingsDialog();
  }
});
长期地址
遇到问题?请前往 GitHub 提 Issues。