Scrollbar Anywhere

By aeosynth Last update Jun 30, 2009 — Installed 250 times. Daily Installs: 1, 0, 1, 7, 0, 0, 1, 0, 0, 3, 1, 3, 0, 2, 1, 2, 0, 0, 2, 0, 11, 0, 1, 0, 1, 2, 0, 2, 4, 0, 3, 0

There are 1 previous version of this script.

// ==UserScript==
// @name           Scrollbar Anywhere
// @description    Use the scrollbar from anywhere on the page, or mimic grab-n-drag style scrolling
// @namespace      aeosynth
// @include        *
// ==/UserScript==

const grabndrag = false// <-- user preference

var X, Y, ratioX, ratioY
window.addEventListener('mousedown', function(e) {if (e.button == 1) start(e)}, true)
function start(e) {
	X = e.clientX
	Y = e.clientY
	ratioX = grabndrag ? -1 : (window.innerWidth + window.scrollMaxX) / window.innerWidth
	ratioY = grabndrag ? -1 : (window.innerHeight + window.scrollMaxY) / window.innerHeight
	window.addEventListener('mousemove', move, true)
	window.addEventListener('mouseup', end, true)
}
function move(e) {
	window.scrollBy( ratioX * (e.clientX - X), ratioY * (e.clientY - Y) )
	X = e.clientX
	Y = e.clientY
}
function end() {
	window.removeEventListener('mousemove', move, true)
	window.removeEventListener('mouseup', end, true)
}