Auto-Scroller

Auto-Scroller, works on mobile and desktop.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Auto-Scroller 
// @version     1.1
// @description Auto-Scroller, works on mobile and desktop.
// @license     CC0-1.0
// @author       Mane
// @match       *://*/*
// @grant       none
// @run-at      document-idle
// @namespace https://greasyfork.org/users/1491313
// ==/UserScript==

;(function(){
  'use strict';

  const SPEED       = 1;    // px per tick
  const INTERVAL_MS = 16;   // ~60fps
  let ticker = null;

  // pick the correct scroll container
  function getScroller(){
    return document.scrollingElement 
        || document.documentElement 
        || document.body;
  }

  function play(){
    if (ticker) return;
    ticker = setInterval(()=>{
      const s = getScroller();
      s.scrollTop = s.scrollTop + SPEED;
    }, INTERVAL_MS);
  }

  function pause(){
    if (!ticker) return;
    clearInterval(ticker);
    ticker = null;
  }

  // build UI once <body> exists
  function init(){
    if (!document.body){
      document.addEventListener('DOMContentLoaded', init, {once:true});
      return;
    }

    const container = document.createElement('div');
    Object.assign(container.style, {
      position:  'fixed',
      bottom:    '20px',
      right:     '20px',
      display:   'flex',
      gap:       '6px',
      zIndex:    999999
    });

    function makeButton(symbol, onClick){
      const btn = document.createElement('button');
      btn.textContent = symbol;
      Object.assign(btn.style, {
        padding:      '8px 12px',
        fontSize:     '18px',
        background:   'rgba(0,0,0,0.6)',
        color:        '#fff',
        border:       'none',
        borderRadius: '6px',
        cursor:       'pointer'
      });
      btn.addEventListener('click', onClick);
      return btn;
    }

    container.append(
      makeButton('▶️', play),
      makeButton('⏸️', pause)
    );
    document.body.appendChild(container);
  }

  init();
})();