My Mouse Gestures

A simple mouse gesture script

目前為 2014-09-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         My Mouse Gestures
// @description  A simple mouse gesture script
// @version      0.0.8
// @include      *
// @run-at       document-start
// @noframes
// @namespace https://gf.qytechs.cn/users/4968
// ==/UserScript==


// --- Settings ---

var SENSITIVITY = 3; // 1 ~ 5
var TOLERANCE = 3; // 1 ~ 5

var funcs = {
	'DR': function() {
		window.open('', '_self', '');
		window.close();
	},
	'DU': function() {
		window.scrollTo(0, 0);
	},
	'UD': function() {
		window.scrollTo(0, 1073741824);
	},
	'L': function() {
		window.history.back();
	},
	'R': function() {
		window.history.forward();
	}
};

// ----------------


var s = 1 << ((7 - SENSITIVITY) << 1);
var t1 = Math.tan(0.15708 * TOLERANCE),
	t2 = 1 / t1;

var x, y, path;

function tracer(e) {
	var cx = e.clientX,
		cy = e.clientY,
		deltaX = cx - x,
		deltaY = cy - y,
		slope = Math.abs(deltaY / deltaX),
		distance = deltaX * deltaX + deltaY * deltaY,
		direction = '';
	if (distance > s) {
		if (slope > t1) {
			if (deltaY > 0) {
				direction = 'D';
			} else {
				direction = 'U';
			}
		} else if (slope <= t2) {
			if (deltaX > 0) {
				direction = 'R';
			} else {
				direction = 'L';
			}
		}
		if (path.slice(-1) != direction) {
			path += direction;
		}
		x = cx;
		y = cy;
	}
}

window.addEventListener('mousedown', function(e) {
	if (e.which == 3) {
		x = e.clientX;
		y = e.clientY;
		path = "";
		window.addEventListener('mousemove', tracer, false);
	}
}, false);

window.addEventListener('contextmenu', function(e) {
	window.removeEventListener('mousemove', tracer, false);
	if (path != "") {
		e.preventDefault();
		if (funcs.hasOwnProperty(path)) {
			funcs[path]();
		}
	}
}, false);

QingJ © 2025

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