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