Last active
May 11, 2020 04:42
-
-
Save yuryshulaev/fce36d11a1a1adc04d49 to your computer and use it in GitHub Desktop.
Greasemonkey drag-style scrolling userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name DragScroll | |
// @include * | |
// @version 1 | |
// @grant none | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js | |
// ==/UserScript== | |
(function ($) { | |
var dragging = false; | |
var initialLeft, initialTop, initialX, initialY; | |
var scrollable = $(window); | |
var button = 3; | |
scrollable.contextmenu(function (e) { | |
return false; | |
}); | |
scrollable.mousedown(function (e) { | |
if (e.which !== button) { | |
return true; | |
} | |
dragging = true; | |
initialLeft = $(this).scrollLeft(); | |
initialTop = $(this).scrollTop(); | |
initialX = e.clientX; | |
initialY = e.clientY; | |
return false; | |
}); | |
scrollable.mousemove(function (e) { | |
if (dragging) { | |
$(this).scrollLeft(initialLeft - (e.clientX - initialX)); | |
$(this).scrollTop(initialTop - (e.clientY - initialY)); | |
return false; | |
} | |
}); | |
scrollable.mouseup(function (e) { | |
if (e.which !== button) { | |
return true; | |
} | |
dragging = false; | |
return false; | |
}); | |
})(jQuery.noConflict(true)); |
I have also used this addon: https://addons.mozilla.org/ru/firefox/addon/scroll_anywhere/ — it has a lot of settings.
Thanks a lot mate. This || e.ctrlKey
is what I was looking for.
However, I was already using that scroll anywhere add on on waterfox, but since I switched to pale moon, it didn't work there and greasemonkey seemed like the only solution. But then someone directed to an old repo of old firefox addons and I found a good alternative to it for pale moon.
Thanks a lot again for your reply mate, I appreciate your help and this little gem of script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. You can change it to use the left mouse button by replacing
if (e.which !== 3) {
withif (e.which !== 1) {
on line 19. To also disable it when Ctrl is being held you can change this line toif (e.which !== 1 || e.ctrlKey) {
. You might also want to remove thescrollable.contextmenu
part (lines 14 to 16) if you use the left button and don’t want to disable context menus.