Scroll with Mouse Plus

Scroll a page by simply moving the cursor up and down, without even a click!

当前为 2022-02-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scroll with Mouse Plus
  3. // @namespace http://userscripts.org/users/86496
  4. // @description Scroll a page by simply moving the cursor up and down, without even a click!
  5. // @include *
  6. // @exclude *pan.baidu.com/*
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_addStyle
  10. // @run-at document-end
  11. // @author hzhbest
  12. // @license GNU GPLv3
  13. // @version 1.18
  14. // ==/UserScript==
  15.  
  16. // Original script by Protector one (http://userscripts.org/scripts/show/63593)
  17. // hzhbest modded; -algorithm changed -compatibility improved -flexabiligy:move into the scrollbar to activate and continue scrolling while in the scroll-sensitive zone
  18.  
  19. (function (){
  20.  
  21. //###Customization: |可自定义的东西:
  22. //Show the scrolling indicator box or not, "1" to show. | 1-显示提示条,其他-不显示。
  23. var scrollShowIndicator = 1;
  24.  
  25. //Set the width of scroll-sensitive zone, "100" as full width, "10" as one tenth.
  26. // | “滚动触发区”宽度,区间:[0-100],100为屏宽,0为禁用,10为十分之一屏宽。
  27. var VScrollonWidth = 10;
  28.  
  29. //Set the background of the indicator bar. | 提示条的背景,可以为“rgba()”带透明色式或“#xxxxxx”实颜色式或其他。
  30. var IndicBarBG = "rgba(29,163,63,0.4)"
  31.  
  32. //Set the height of "thickness" of the indicator bar. | 提示条的粗细度,单位为像素。
  33. var IndicBarH = 20;
  34.  
  35. //Write here the width of the scrollbar (set in display properties) for highest accuracy.
  36. // | 在下面填写滚动条的宽度(也就是系统“显示属性”中的数字),这样能实现最高精确度。
  37. var ScrollbarWidth = 20;
  38.  
  39. //Set a trigger for activation, 1-none, 2-Ctrl key, 3-middle 100px range.
  40. // | 在下面设置激活条件,1-无,2-按住 Ctrl 键,3-鼠标在页面中间100像素高度范围内。
  41. var activateCond = 1;
  42.  
  43.  
  44. //###Customization ends. 请不要更改下面代码。
  45. var scrollStartSWTM = -1;
  46.  
  47. var factor;
  48. var b=0;
  49. var VScrollOn=0;
  50.  
  51. document.addEventListener('mousemove', function(event) {
  52. if (document.body.contentEditable == "true") {
  53. return;
  54. }
  55. var dheightMax = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  56. var cwidthMax = Math.max(document.body.clientWidth, document.documentElement.clientWidth);
  57. var cwinHeight = window.innerHeight;
  58. var scrollboxHeight = window.innerHeight - 2*ScrollbarWidth
  59. //var cheightMin = Math.min(document.documentElement.clientHeight, document.body.clientHeight);
  60. //alert(cwidthMax);
  61. if (dheightMax > cwinHeight) {
  62. if (event.clientX > cwidthMax - ScrollbarWidth)
  63. switch (activateCond) {
  64. case 1:
  65. VScrollOn = 1;
  66. break;
  67. case 2:
  68. if (event.ctrlKey) VScrollOn = 1;
  69. break;
  70. case 3:
  71. if (event.clientY>cwinHeight/2-50 && event.clientY<cwinHeight/2+50) VScrollOn = 1;
  72. };
  73. if (event.clientX < ((1-VScrollonWidth/100) * cwidthMax)) VScrollOn = 0;
  74. if (document.body.contentEditable == "true") VScrollOn = 0;
  75. }
  76. if (VScrollOn) {
  77. if (scrollShowIndicator == 1)make_boxes();
  78. if (scrollStartSWTM != -1) {
  79. factor = (event.ctrlKey) ? dheightMax / scrollboxHeight / 2 : dheightMax / scrollboxHeight;
  80. //factor = ((Math.pow(dheightMax / cwinHeight,1.5)/110) + dheightMax / cwinHeight);
  81. //b.innerHTML = cwinHeight +"|"+scrollboxHeight +"<br />"+dheightMax +"|"+ factor +"<br />"+document.body.scrollTop;
  82. if (b) {b.style.top = (event.clientY - IndicBarH/2) + 'px';}
  83. var delta = factor * (event.clientY - scrollStartSWTM);
  84. document.body.scrollTop += delta;
  85. document.documentElement.scrollTop += delta;
  86. if (event.clientY + 20 > cwinHeight) {
  87. document.body.scrollTop += (factor * 10);
  88. document.documentElement.scrollTop += (factor * 10);
  89. }
  90. if (event.clientY > 0 && event.clientY < 20) {
  91. document.body.scrollTop -= (factor * 10);
  92. document.documentElement.scrollTop -= (factor * 10);
  93. }
  94. }
  95. scrollStartSWTM = event.clientY;
  96. }
  97. else
  98. {
  99. scrollStartSWTM = -1;
  100. if (b) setTimeout(function(){b.style.top = -200 + 'px';},200);
  101. }
  102. },false);
  103. document.addEventListener('click',function(){VScrollOn=0;},false);
  104.  
  105. function make_boxes() {
  106. if (!b) {
  107. b = document.createElement("div");
  108. b.setAttribute("id","IndicatorBox");
  109. b.setAttribute("style", "width:" + VScrollonWidth +"%;background:" + IndicBarBG + ";min-height:" +IndicBarH + "px;text-align:center;position: fixed; top: -40px; right: 0;overflow: hidden; z-index: 10005;font-family:Arial !important;cursor:n-resize;cursor:ns-resize;");
  110. document.body.appendChild(b);
  111. b.addEventListener('click',function(){VScrollOn=0;},false);
  112. return true;
  113. }
  114. }
  115.  
  116. })();