页面自动滚动

通过使用快捷键实现页面自动滚动

  1.  
  2. // ==UserScript==
  3. // @name 页面自动滚动
  4. // @namespace eyes
  5. // @version 1.6.0
  6. // @description 通过使用快捷键实现页面自动滚动
  7. // @author eyes
  8. // @match *://*/*
  9. // @grant none
  10. // @supportURL https://eyesblog.gitee.io/
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. let speed = 0;
  16. let speed_num = 1.5; // 修改这个调整滚动速度
  17. let getScrollTop = () => {
  18. var scrollTop = 0,
  19. bodyScrollTop = 0,
  20. documentScrollTop = 0;
  21. if (document.body) {
  22. bodyScrollTop = document.body.scrollTop;
  23. }
  24. if (document.documentElement) {
  25. documentScrollTop = document.documentElement.scrollTop;
  26. }
  27. scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
  28. return scrollTop;
  29. }
  30. let getWindowHeight = () => {
  31. var windowHeight = 0;
  32. if (document.compatMode == 'CSS1Compat') {
  33. windowHeight = document.documentElement.clientHeight;
  34. } else {
  35. windowHeight = document.body.clientHeight;
  36. }
  37. return windowHeight;
  38. }
  39. let getScrollHeight = () => {
  40. var scrollHeight = 0,
  41. bodyScrollHeight = 0,
  42. documentScrollHeight = 0;
  43. if (document.body) {
  44. bodyScrollHeight = document.body.scrollHeight;
  45. }
  46. if (document.documentElement) {
  47. documentScrollHeight = document.documentElement.scrollHeight;
  48. }
  49. scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
  50. return scrollHeight;
  51. }
  52. setInterval(() => {
  53. let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
  54. let topFlag = (getScrollTop() == 0) ? true : false;
  55. if (bottomFlag || topFlag) {
  56. speed = 0;
  57. } else {
  58. document.documentElement.scrollTop += speed;
  59. }
  60. }, 5)
  61. document.onkeydown = (e) => {
  62. e = event || window.event;
  63. // 同时按上键与alt键向上滚动
  64. if (e && e.keyCode == 38 && e.altKey) {
  65. let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
  66. if (bottomFlag) {
  67. document.documentElement.scrollTop += -1;
  68. }
  69. speed -= speed_num;
  70. }
  71. // 同时按下键与alt键向下滚动
  72. if (e && e.keyCode == 40 && e.altKey) {
  73. let topFlag = (getScrollTop() == 0) ? true : false;
  74. if (topFlag) {
  75. document.documentElement.scrollTop += 1;
  76. }
  77. speed += speed_num;
  78. }
  79. // 同时按 CTRL + ALT 键停止滚动
  80. if (e && e.altKey && e.ctrlKey) {
  81. speed = 0;
  82. }
  83. }
  84. // 单击页面停止滚动
  85. document.onclick = () => {
  86. speed = 0;
  87. }
  88. // 滑动滚轮页面停止滚动
  89. document.onmousewheel = () => {
  90. speed = 0;
  91. }
  92. document.addEventListener("DOMMouseScroll", () => {
  93. speed = 0;
  94. })
  95. })();
  96.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址