🏠 

Scroll with Mouse Plus

页面随心滚动,无需点击!


安装此脚本?
  1. // ==UserScript==
  2. // @name Scroll with Mouse Plus
  3. // @name:en Scroll with Mouse Plus
  4. // @name:zh-CN Scroll with Mouse Plus
  5. // @namespace http://userscripts.org/users/86496
  6. // @description:zh-CN 页面随心滚动,无需点击!
  7. // @description:en Scroll a page by simply moving the cursor, without even a click!
  8. // @include *
  9. // @exclude *pan.baidu.com/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @run-at document-end
  14. // @author hzhbest
  15. // @license GNU GPLv3
  16. // @version 2.11
  17. // @description Scroll a page by simply moving the cursor up and down, without even a click!
  18. // ==/UserScript==
  19. // Original script by Protector one (http://userscripts.org/scripts/show/63593)
  20. // hzhbest modded; -algorithm changed -compatibility improved -flexabiligy:move into the scrollbar to activate and continue scrolling while in the scroll-sensitive zone
  21. // v20: add horizontal scroll support
  22. (function (){
  23. //###Customization: |可自定义的东西:
  24. //Show the scrolling indicator box or not, "1" to show. | 1-显示提示条,其他-不显示。
  25. var scrollShowIndicator = 1;
  26. //Set the width of scroll-sensitive zone, "100" as full width, "10" as one tenth.
  27. // | “滚动触发区”宽度百分比,区间:[0-100],V为垂直宽度,H为水平宽度;取值100为屏宽/高,0为禁用,10为十分之一屏宽/高。
  28. var VSzoneWidth = 10;
  29. var HSzoneHeight = 20;
  30. //Set the background of the indicator bar. | 提示条的背景,可以为“rgba(r,g,b,a)”或“#rrggbb[aa]”格式。
  31. var IndicBarBG = "rgba(29,163,63,0.4)";
  32. //Set the height of "thickness" of the indicator bar. | 提示条的粗细度,单位为像素。
  33. var IndicBarH = 20;
  34. //Write here the width of the scrollbar (set in display properties) for highest accuracy.
  35. // | 在下面填写滚动条的宽度(也就是系统“显示属性”中的数字),这样能实现最高精确度。
  36. var ScrollbarWidth = 30;
  37. //Set a trigger for activation, 1-none, 2-Ctrl key, 3-middle 100px range.
  38. // | 在下面设置激活条件,1-无,2-按住 Ctrl 键,3-鼠标在页面中间100像素高度范围内。
  39. var activateCond = 1;
  40. //Set if active on side(s)
  41. // | 设置是否在某些边启用。
  42. var actOnLeft = false;
  43. var actOnRight = true;
  44. var actOnBottom = true;
  45. //###Customization ends. 请不要更改下面代码。
  46. var VscrollStartSWTM = -1;
  47. var HscrollStartSWTM = -1;
  48. var factor;
  49. var Vbox;
  50. var Hbox;
  51. var VonL = 0;
  52. var VScrollOn = 0;
  53. var HScrollOn = false;
  54. document.addEventListener('mousemove', function(event) {
  55. if (document.body.contentEditable == "true") {
  56. return;
  57. }
  58. // sHeight,sWidth:内容高度、宽度
  59. var sHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  60. var sWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
  61. // var cHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  62. // var cWidth = Math.max(document.body.clientWidth, document.documentElement.clientWidth);
  63. // wHeight,wWidth:窗口(内容框)高度、宽度
  64. var wHeight = window.innerHeight;
  65. var wWidth = window.innerWidth;
  66. // scrollboxHeight,Width:减去滚动条的滚动范围高度、宽度
  67. var scrollboxHeight = wHeight - 2 * ScrollbarWidth;
  68. var scrollboxWidth = wWidth - 2 * ScrollbarWidth;
  69. // 滚动量
  70. var delta;
  71. //console.log("1:","x:",event.clientX,"y:",event.clientY,"h_on",HScrollOn);
  72. if (sHeight > wHeight) { // 仅当内容高度大于窗口高度时响应垂直滚动激活
  73. var shouldActiveL = actOnLeft && event.clientX < ScrollbarWidth;
  74. var shouldActiveR = actOnRight && event.clientX > wWidth - ScrollbarWidth;
  75. if (shouldActiveL) {
  76. VonL = 1;
  77. } else if (shouldActiveR) {
  78. VonL = 2;
  79. }
  80. if (shouldActiveL || shouldActiveR){
  81. switch (activateCond) {
  82. case 1:
  83. VScrollOn = VonL;
  84. break;
  85. case 2:
  86. if (event.ctrlKey) VScrollOn = VonL;
  87. break;
  88. case 3:
  89. if (event.clientY>wHeight/2-50 && event.clientY<wHeight/2+50) VScrollOn = VonL;
  90. }
  91. if (VScrollOn) HScrollOn = false;
  92. }
  93. var shouldExitL = VonL == 1 && event.clientX > VSzoneWidth / 100 * wWidth;
  94. var shouldExitR = VonL == 2 && event.clientX < (1 - VSzoneWidth / 100) * wWidth;
  95. if (shouldExitL || shouldExitR) VScrollOn = 0;
  96. if (document.body.contentEditable == "true") VScrollOn = 0;
  97. }
  98. if (actOnBottom && sWidth > wWidth) { // 仅当内容宽度大于窗口宽度时响应水平滚动激活
  99. if (event.clientY > wHeight - ScrollbarWidth){
  100. switch (activateCond) {
  101. case 1:
  102. HScrollOn = true;
  103. break;
  104. case 2:
  105. if (event.ctrlKey) HScrollOn = true;
  106. break;
  107. case 3:
  108. if (event.clientX>wWidth/2-50 && event.clientX<wWidth/2+50) HScrollOn = true;
  109. };
  110. if (HScrollOn) VScrollOn = 0;
  111. }
  112. if (event.clientY < ((1-HSzoneHeight/100) * wHeight)) HScrollOn = false;
  113. if (document.body.contentEditable == "true") HScrollOn = false;
  114. }
  115. if (VScrollOn) {
  116. if (scrollShowIndicator == 1) make_Vbox();
  117. if (VscrollStartSWTM != -1) {
  118. factor = (event.ctrlKey) ? 2: sHeight / scrollboxHeight;
  119. //console.log("w:",sHeight,scrollboxHeight,factor);
  120. //factor = ((Math.pow(dheightMax / wHeight,1.5)/110) + dheightMax / wHeight);
  121. //Vbox.innerHTML = wHeight +"|"+scrollboxHeight +"<br />"+dheightMax +"|"+ factor +"<br />"+document.body.scrollTop;
  122. if (Vbox) {
  123. Vbox.style.top = (event.clientY - IndicBarH / 2) + 'px';
  124. Vbox.style.left = VonL == 1 ? "0px" : "unset";
  125. Vbox.style.right = VonL == 2 ? "0px" : "unset";
  126. }
  127. delta = factor * (event.clientY - VscrollStartSWTM);
  128. document.body.scrollTop += delta;
  129. document.documentElement.scrollTop += delta;
  130. if (event.clientY + 20 > wHeight) {
  131. document.body.scrollTop += (factor * 10);
  132. document.documentElement.scrollTop += (factor * 10);
  133. }
  134. if (event.clientY > 0 && event.clientY < 20) {
  135. document.body.scrollTop -= (factor * 10);
  136. document.documentElement.scrollTop -= (factor * 10);
  137. }
  138. }
  139. VscrollStartSWTM = event.clientY;
  140. } else {
  141. VscrollStartSWTM = -1;
  142. if (Vbox) setTimeout(function(){Vbox.style.top = -200 + 'px';},200);
  143. }
  144. if (HScrollOn) {
  145. if (scrollShowIndicator == 1) make_Hbox();
  146. if (HscrollStartSWTM != -1) {
  147. factor = (event.ctrlKey) ? 0.5 : sWidth / scrollboxWidth;
  148. //console.log("w:",sWidth,scrollboxWidth,factor);
  149. //factor = ((Math.pow(dheightMax / wHeight,1.5)/110) + dheightMax / wHeight);
  150. if (Hbox) {Hbox.style.left = (event.clientX - IndicBarH/2) + 'px';}
  151. delta = factor * (event.clientX - HscrollStartSWTM);
  152. document.body.scrollLeft += delta;
  153. document.documentElement.scrollLeft += delta;
  154. if (event.clientX + 20 > wWidth) {
  155. document.body.scrollLeft += (factor * 10);
  156. document.documentElement.scrollLeft += (factor * 10);
  157. }
  158. if (event.clientX > 0 && event.clientX < 20) {
  159. document.body.scrollLeft -= (factor * 10);
  160. document.documentElement.scrollLeft -= (factor * 10);
  161. }
  162. }
  163. HscrollStartSWTM = event.clientX;
  164. } else {
  165. HscrollStartSWTM = -1;
  166. if (Hbox) setTimeout(function(){Hbox.style.left = -200 + 'px';},200);
  167. }
  168. },false);
  169. document.addEventListener('click', function () {
  170. VScrollOn = 0;
  171. HScrollOn = false;
  172. }, false);
  173. function make_Vbox() {
  174. if (!Vbox) {
  175. Vbox = document.createElement("div");
  176. Vbox.id = "IndicatorVBox";
  177. var css = "width:" + VSzoneWidth + "%; background:" + IndicBarBG + "; min-height:" + IndicBarH + "px;";
  178. css += "text-align:center; position: fixed; top: -40px; overflow: hidden; z-index: 9999999; font-family:Arial !important; cursor:ns-resize;";
  179. Vbox.style = css;
  180. document.body.appendChild(Vbox);
  181. Vbox.addEventListener('click',function(){VScrollOn=0;},false);
  182. return true;
  183. }
  184. }
  185. function make_Hbox() {
  186. if (!Hbox) {
  187. Hbox = document.createElement("div");
  188. Hbox.id = "IndicatorHBox";
  189. Hbox.style = "height:" + HSzoneHeight +"%;background:" + IndicBarBG + ";min-width:" +IndicBarH + "px;text-align:center;position: fixed; left: -40px; bottom: 0;overflow: hidden; z-index: 9999999;font-family:Arial !important;cursor:ew-resize;";
  190. document.body.appendChild(Hbox);
  191. Hbox.addEventListener('click',function(){HScrollOn=false;},false);
  192. return true;
  193. }
  194. }
  195. })();