AutoScroll1234

AutoScroll-自动滚屏

当前为 2021-06-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        AutoScroll1234
// @namespace   
// @description AutoScroll-自动滚屏
// @include     http*
// @version     v1.6
// @author      nosura
// @grant       none
// ==/UserScript==

// 滚动条在Y轴上的滚动距离
function getScrollTop() {
  let scrollTop = 0
  let bodyScrollTop = 0
  let documentScrollTop = 0
  if (document.body) {
    bodyScrollTop = document.body.scrollTop
  }
  if (document.documentElement) {
    documentScrollTop = document.documentElement.scrollTop
  }
  scrollTop =
    bodyScrollTop - documentScrollTop > 0 ? bodyScrollTop : documentScrollTop
  return scrollTop
}
// 文档的总高度
function getScrollHeight() {
  let scrollHeight = 0,
    bodyScrollHeight = 0,
    documentScrollHeight = 0
  if (document.body) {
    bodyScrollHeight = document.body.scrollHeight
  }
  if (document.documentElement) {
    documentScrollHeight = document.documentElement.scrollHeight
  }
  scrollHeight =
    bodyScrollHeight - documentScrollHeight > 0
      ? bodyScrollHeight
      : documentScrollHeight
  return scrollHeight
}
// 浏览器视口的高度
function getWindowHeight() {
  return document.body.clientHeight
}

let timer
let startAt = Date.now()

window.onscroll = () => {
  if (getScrollTop() + getWindowHeight() >= getScrollHeight()) {
    if (Date.now() - startAt < 8000) {
      setTimeout(() => {
        window.location.reload()
      }, Date.now() - startAt )
    } else {
      window.location.reload()
    }
  }
}

window.onload = () => {
  setTimeout(() => {
    if (getScrollTop() + getWindowHeight() >= getScrollHeight()) {
      setTimeout(() => {
        window.location.reload()
      }, 8000)
    } else {
      setInterval(() => {
        window.scroll(0, window.scrollY + 1)
      }, 50)
    }
  }, 2000)
}