AutoScroll1234

AutoScroll-自动滚屏

  1. // ==UserScript==
  2. // @name AutoScroll1234
  3. // @namespace
  4. // @description AutoScroll-自动滚屏
  5. // @include http*
  6. // @version v1.6
  7. // @author nosura
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // 滚动条在Y轴上的滚动距离
  12. function getScrollTop() {
  13. let scrollTop = 0
  14. let bodyScrollTop = 0
  15. let documentScrollTop = 0
  16. if (document.body) {
  17. bodyScrollTop = document.body.scrollTop
  18. }
  19. if (document.documentElement) {
  20. documentScrollTop = document.documentElement.scrollTop
  21. }
  22. scrollTop =
  23. bodyScrollTop - documentScrollTop > 0 ? bodyScrollTop : documentScrollTop
  24. return scrollTop
  25. }
  26. // 文档的总高度
  27. function getScrollHeight() {
  28. let scrollHeight = 0,
  29. bodyScrollHeight = 0,
  30. documentScrollHeight = 0
  31. if (document.body) {
  32. bodyScrollHeight = document.body.scrollHeight
  33. }
  34. if (document.documentElement) {
  35. documentScrollHeight = document.documentElement.scrollHeight
  36. }
  37. scrollHeight =
  38. bodyScrollHeight - documentScrollHeight > 0
  39. ? bodyScrollHeight
  40. : documentScrollHeight
  41. return scrollHeight
  42. }
  43. // 浏览器视口的高度
  44. function getWindowHeight() {
  45. return document.body.clientHeight
  46. }
  47.  
  48. let timer
  49. let startAt = Date.now()
  50.  
  51. window.onscroll = () => {
  52. if (getScrollTop() + getWindowHeight() >= getScrollHeight()) {
  53. if (Date.now() - startAt < 8000) {
  54. setTimeout(() => {
  55. window.location.reload()
  56. }, Date.now() - startAt )
  57. } else {
  58. window.location.reload()
  59. }
  60. }
  61. }
  62.  
  63. window.onload = () => {
  64. setTimeout(() => {
  65. if (getScrollTop() + getWindowHeight() >= getScrollHeight()) {
  66. setTimeout(() => {
  67. window.location.reload()
  68. }, 8000)
  69. } else {
  70. setInterval(() => {
  71. window.scroll(0, window.scrollY + 1)
  72. }, 50)
  73. }
  74. }, 2000)
  75. }