Scroll with Mouse Plus

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

目前为 2023-02-16 提交的版本。查看 最新版本

// ==UserScript==
// @name           Scroll with Mouse Plus
// @name:zh-CN     Scroll with Mouse Plus
// @name:en        Scroll with Mouse Plus
// @namespace      http://userscripts.org/users/86496
// @description:zh-CN    页面随心滚动,无需点击!
// @description:en Scroll a page by simply moving the cursor, without even a click!
// @include        *
// @exclude		   *pan.baidu.com/*
// @grant		   GM_getValue
// @grant		   GM_setValue
// @grant		   GM_addStyle
// @run-at		   document-end
// @author         hzhbest
// @license        GNU GPLv3
// @version        2.0
// @description Scroll a page by simply moving the cursor up and down, without even a click!
// ==/UserScript==

// Original script by Protector one (http://userscripts.org/scripts/show/63593)
// hzhbest modded; -algorithm changed -compatibility improved -flexabiligy:move into the scrollbar to activate and continue scrolling while in the scroll-sensitive zone
// v20: add horizontal scroll support

(function (){

//###Customization: |可自定义的东西:

  //Show the scrolling indicator box or not, "1" to show. | 1-显示提示条,其他-不显示。
var scrollShowIndicator = 1;

  //Set the width of scroll-sensitive zone, "100" as full width, "10" as one tenth.
  // | “滚动触发区”宽度百分比,区间:[0-100],V为垂直宽度,H为水平宽度;取值100为屏宽/高,0为禁用,10为十分之一屏宽/高。
var VSzoneWidth = 10;
var HSzoneHeight = 20;

  //Set the background of the indicator bar. | 提示条的背景,可以为“rgba(r,g,b,a)”或“#rrggbb[aa]”格式。
var IndicBarBG = "rgba(29,163,63,0.4)"

  //Set the height of "thickness" of the indicator bar. | 提示条的粗细度,单位为像素。
var IndicBarH = 20;

  //Write here the width of the scrollbar (set in display properties) for highest accuracy.
  // | 在下面填写滚动条的宽度(也就是系统“显示属性”中的数字),这样能实现最高精确度。
var ScrollbarWidth = 30;

  //Set a trigger for activation, 1-none, 2-Ctrl key, 3-middle 100px range.
  // | 在下面设置激活条件,1-无,2-按住 Ctrl 键,3-鼠标在页面中间100像素高度范围内。
var activateCond = 1;


//###Customization ends. 请不要更改下面代码。
var VscrollStartSWTM = -1;
var HscrollStartSWTM = -1;
var factor;
var Vbox;
var Hbox;
var VScrollOn=0;
var HScrollOn=0;

	document.addEventListener('mousemove', function(event) {
        if (document.body.contentEditable == "true") {
            return;
        }
		var sHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
		var sWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
		var cHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
		var cWidth = Math.max(document.body.clientWidth, document.documentElement.clientWidth);
		var wHeight = window.innerHeight;
		var wWidth = window.innerWidth;
		var scrollboxHeight = window.innerHeight - 2*ScrollbarWidth;
		var scrollboxWidth = window.innerWidth - 2*ScrollbarWidth;
		var delta;
		//var cheightMin = Math.min(document.documentElement.clientHeight, document.body.clientHeight);
		//console.log("1:","x:",event.clientX,"y:",event.clientY,"h_on",HScrollOn);
		if (sHeight > wHeight) {
			if (event.clientX > wWidth - ScrollbarWidth){
				switch (activateCond) {
					case 1:
						VScrollOn = 1;
						break;
					case 2:
						if (event.ctrlKey) VScrollOn = 1;
						break;
					case 3:
						if (event.clientY>wHeight/2-50 && event.clientY<wHeight/2+50) VScrollOn = 1;
				};
				if (VScrollOn) HScrollOn = 0;
			}
			if (event.clientX < ((1-VSzoneWidth/100) * wWidth)) VScrollOn = 0;
			if (document.body.contentEditable == "true") VScrollOn = 0;
		}
		if (sWidth > wWidth) {
			if (event.clientY > wHeight - ScrollbarWidth){
				switch (activateCond) {
					case 1:
						HScrollOn = 1;
						break;
					case 2:
						if (event.ctrlKey) HScrollOn = 1;
						break;
					case 3:
						if (event.clientX>wWidth/2-50 && event.clientX<wWidth/2+50) HScrollOn = 1;
				};
				if (HScrollOn) VScrollOn = 0;
			}
			if (event.clientY < ((1-HSzoneHeight/100) * wHeight)) HScrollOn = 0;
			if (document.body.contentEditable == "true") HScrollOn = 0;
		}
		if (VScrollOn) {
			if (scrollShowIndicator == 1) make_Vbox();
			if (VscrollStartSWTM != -1) {
				factor = (event.ctrlKey) ? 2: sHeight / scrollboxHeight;
                //console.log("w:",sHeight,scrollboxHeight,factor);
				//factor = ((Math.pow(dheightMax / wHeight,1.5)/110) + dheightMax / wHeight);
				//Vbox.innerHTML = wHeight +"|"+scrollboxHeight +"<br />"+dheightMax +"|"+ factor +"<br />"+document.body.scrollTop;
				if (Vbox) {Vbox.style.top = (event.clientY - IndicBarH/2) + 'px';}
				delta = factor * (event.clientY - VscrollStartSWTM);
				document.body.scrollTop += delta;
				document.documentElement.scrollTop += delta;
				if (event.clientY + 20 > wHeight) {
					document.body.scrollTop += (factor * 10);
					document.documentElement.scrollTop += (factor * 10);
				}
				if (event.clientY > 0 && event.clientY < 20) {
					document.body.scrollTop -= (factor * 10);
					document.documentElement.scrollTop -= (factor * 10);
				}
			}
		VscrollStartSWTM = event.clientY;
		} else {
			VscrollStartSWTM = -1;
			if (Vbox) setTimeout(function(){Vbox.style.top = -200 + 'px';},200);
		}
		if (HScrollOn) {
			if (scrollShowIndicator == 1) make_Hbox();
			if (HscrollStartSWTM != -1) {
				factor = (event.ctrlKey) ? 0.5 : sWidth / scrollboxWidth;
                //console.log("w:",sWidth,scrollboxWidth,factor);
				//factor = ((Math.pow(dheightMax / wHeight,1.5)/110) + dheightMax / wHeight);
				if (Hbox) {Hbox.style.left = (event.clientX - IndicBarH/2) + 'px';}
				delta = factor * (event.clientX - HscrollStartSWTM);
				document.body.scrollLeft += delta;
				document.documentElement.scrollLeft += delta;
				if (event.clientX + 20 > wWidth) {
					document.body.scrollLeft += (factor * 10);
					document.documentElement.scrollLeft += (factor * 10);
				}
				if (event.clientX > 0 && event.clientX < 20) {
					document.body.scrollLeft -= (factor * 10);
					document.documentElement.scrollLeft -= (factor * 10);
				}
			}
		HscrollStartSWTM = event.clientX;
		} else {
			HscrollStartSWTM = -1;
			if (Hbox) setTimeout(function(){Hbox.style.left = -200 + 'px';},200);
		}
	},false);
	document.addEventListener('click',function(){VScrollOn=0;HScrollOn=0;},false);


    function make_Vbox() {
        if (!Vbox) {
            Vbox = document.createElement("div");
            Vbox.setAttribute("id","IndicatorVBox");
            Vbox.setAttribute("style", "width:" + VSzoneWidth +"%;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:ns-resize;");
            document.body.appendChild(Vbox);
			Vbox.addEventListener('click',function(){VScrollOn=0;},false);
            return true;
        }
	}
    function make_Hbox() {
        if (!Hbox) {
            Hbox = document.createElement("div");
            Hbox.setAttribute("id","IndicatorHBox");
            Hbox.setAttribute("style", "height:" + HSzoneHeight +"%;background:" + IndicBarBG + ";min-width:" +IndicBarH + "px;text-align:center;position: fixed; left: -40px; bottom: 0;overflow: hidden; z-index: 10005;font-family:Arial !important;cursor:ew-resize;");
            document.body.appendChild(Hbox);
			Hbox.addEventListener('click',function(){HScrollOn=0;},false);
            return true;
        }
	}

})();

QingJ © 2025

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