forked from defpt/userChromeJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollWithMouse.uc.js
38 lines (36 loc) · 1.64 KB
/
ScrollWithMouse.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ==UserScript==
// @name ScrollWithMouse.uc.js
// @namespace [email protected]
// @description 免点击鼠标拖动,来自Mozest.com社区
// ==/UserScript==
(function(){
var speed = 1;
var scrollMode = 0;
var scrollStartSWTM = -1;
function mouseScroll(event) {
if (scrollStartSWTM != -1){
var document = window.content.document;
if(document.body instanceof HTMLFrameSetElement) {
document = window.content.frames[0].document; }
var factor = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) / window.content.innerHeight;
var delta = speed*factor*(event.screenY - scrollStartSWTM);
document.body.scrollTop += delta;
document.documentElement.scrollTop += delta;
}
scrollStartSWTM = event.screenY;
}
function startScroll() {
if(!scrollMode){
scrollMode = 1;
window.addEventListener('mousemove', mouseScroll, true)}}
function stopScroll() {
if(scrollMode){
scrollMode = 0;
scrollStartSWTM = -1;
window.removeEventListener('mousemove', mouseScroll, true)}}
var content=document.getElementById("content")
content.addEventListener("mousemove", function(e) {
if (e.clientX > window.content.document.documentElement.clientWidth){startScroll();}
},false);
content.addEventListener("mouseout", function(e) {stopScroll();},false);
})();