AutoScroller UI Plus ✨

自动滚动页面,rAF 丝滑驱动 + 可调速面板(兼容无限下拉)

目前為 2025-05-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AutoScroller UI Plus ✨
// @namespace    https://example.com/
// @version      0.4
// @description  自动滚动页面,rAF 丝滑驱动 + 可调速面板(兼容无限下拉)
// @author       你
// @license      MIT
// @match        *://*/*
// @icon         https://example.com/icon.png
// @grant        GM_addStyle
// ==/UserScript==


(function () {
  'use strict';

  /* ——— 可自定义变量 ——— */
  let su_du = 200;        // 滚动速度(px / 秒)← 可自定义
  let yun_xing = false;   // 运行标志
  let shang_ci = 0;       // 上次帧时间戳

  /* ——— 创建 UI ——— */
  const kuang = document.createElement('div');
  kuang.id = 'autoScrollerPanel';
  kuang.innerHTML = `
    <header id="tiaoTi">自动滚动 ⇲</header>
    <div class="neiRong">
      <label>速度(px/s):
        <input type="number" id="suDuInput" value="${su_du}" />
      </label>
      <div class="btns">
        <button id="kaiShiBtn">开始 🚀</button>
        <button id="tingZhiBtn">停止 🛑</button>
      </div>
    </div>
  `;
  document.body.appendChild(kuang);

  /* ——— 样式 ——— */
  GM_addStyle(`
    :root{
      --as-main:#6366f1;
      --as-main-light:#8b97ff;
      --as-bg:rgba(255,255,255,0.85);
    }
    #autoScrollerPanel{
      position:fixed; bottom:20px; right:20px;
      width:190px; border-radius:12px; z-index:9999;
      box-shadow:0 4px 18px rgba(0,0,0,.15);
      backdrop-filter:blur(10px); background:var(--as-bg);
      font-size:14px; color:#111; user-select:none;
      transition:box-shadow .2s;
    }
    #autoScrollerPanel header{
      background:var(--as-main); color:#fff;
      padding:8px 12px; border-radius:12px 12px 0 0;
      cursor:move; font-weight:600; letter-spacing:.5px;
    }
    #autoScrollerPanel .neiRong{padding:12px 14px;}
    #autoScrollerPanel input{
      width:78px; margin-left:4px; padding:2px 4px;
      border:1px solid #ccc; border-radius:6px;
    }
    #autoScrollerPanel .btns{margin-top:10px; display:flex; gap:8px;}
    #autoScrollerPanel button{
      flex:1; padding:6px 0; border:none; border-radius:8px;
      background:var(--as-main); color:#fff; font-weight:500;
      box-shadow:0 2px 6px rgba(0,0,0,.15);
      transition:transform .2s, background .2s, box-shadow .2s;
      cursor:pointer;
    }
    #autoScrollerPanel button:hover{
      background:var(--as-main-light); transform:translateY(-2px);
      box-shadow:0 6px 12px rgba(0,0,0,.2);
    }
  `);

  /* ——— 事件 ——— */
  const suDuInput = kuang.querySelector('#suDuInput');
  const kaiShiBtn = kuang.querySelector('#kaiShiBtn');
  const tingZhiBtn = kuang.querySelector('#tingZhiBtn');

  kaiShiBtn.addEventListener('click', () => {
    su_du = parseFloat(suDuInput.value) || su_du;
    if (yun_xing) return;          // 已在跑
    yun_xing = true;
    shang_ci = 0;
    requestAnimationFrame(gunDong);
  });

  tingZhiBtn.addEventListener('click', () => {
    yun_xing = false;
  });

  /* ——— 核心滚动 (rAF) ——— */
  function gunDong(time){
    if (!yun_xing) return;
    if (!shang_ci) shang_ci = time;
    const cha = time - shang_ci;           // Δt (ms)
    const bu_chang = su_du * cha / 1000;   // Δs = 速度 * 时间
    const diBuCha = document.body.scrollHeight - (window.scrollY + window.innerHeight);

    if (diBuCha > 0) window.scrollBy(0, bu_chang);
    // 到底部但可能懒加载 → 维持循环
    shang_ci = time;
    requestAnimationFrame(gunDong);
  }

  /* ——— 面板拖拽 ——— */
  (function drag(el, handle){
    let startX, startY, startL, startT, z = 9999;
    handle.addEventListener('mousedown', e=>{
      startX = e.clientX; startY = e.clientY;
      const rect = el.getBoundingClientRect();
      startL = rect.left; startT = rect.top;
      el.style.transition = 'none';
      document.addEventListener('mousemove', move);
      document.addEventListener('mouseup', up, {once:true});
      e.preventDefault();
    });
    function move(e){
      el.style.left = startL + (e.clientX - startX) + 'px';
      el.style.top  = startT + (e.clientY - startY) + 'px';
      el.style.right = 'auto'; el.style.bottom = 'auto';
      el.style.position = 'fixed'; el.style.zIndex = ++z;
    }
    function up(){ document.removeEventListener('mousemove', move); }
  })(kuang, kuang.querySelector('#tiaoTi'));
})();