Last active
February 20, 2016 22:14
-
-
Save r-a-y/b2a787736146ed8cab66 to your computer and use it in GitHub Desktop.
Mouse gestures script for the Conkeror browser - http://conkeror.org
This file contains hidden or 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
// Mouse Gestures for Conkeror by r-a-y. | |
// | |
// Modified from the Mouse Gestures By Sing Chu userscript: | |
// http://userscripts-mirror.org/scripts/show/162193 | |
var BTN_RIGHT = 2; | |
var SENSITIVITY = 15; //Pixels moved until gesture is registered | |
var startX; | |
var startY; | |
var gesture = ""; | |
var gestures = { | |
l : function(){get_recent_conkeror_window().buffers.current.web_navigation.goBack()}, | |
r : function(){get_recent_conkeror_window().buffers.current.web_navigation.goForward()}, | |
ud : function(){get_recent_conkeror_window().buffers.current.web_navigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE)}, | |
dr : function(){kill_buffer(get_recent_conkeror_window().buffers.current)}, | |
} | |
function mgMouseDown(e){ | |
if(e.button == BTN_RIGHT) { | |
startX = e.clientX; | |
startY = e.clientY; | |
gesture = ""; | |
get_recent_conkeror_window().buffers.current.browser.addEventListener("mousemove",mgMouseMove,true); | |
get_recent_conkeror_window().buffers.current.browser.addEventListener("mouseup",mgMouseUp,true); | |
} | |
} | |
function mgMouseMove(e){ | |
checkMove(startY - e.clientY, 'u', e); | |
checkMove(e.clientX - startX, 'r', e); | |
checkMove(e.clientY - startY, 'd', e); | |
checkMove(startX - e.clientX, 'l', e); | |
} | |
function checkMove(p, t, e) { | |
if (p >= SENSITIVITY) { | |
startX = e.clientX; | |
startY = e.clientY; | |
if (gesture[gesture.length-1] != t) { | |
gesture += t; | |
} | |
} | |
} | |
function mgMouseUp(e) { | |
if (gestures[gesture]) { | |
gestures[gesture](); | |
} | |
get_recent_conkeror_window().buffers.current.browser.removeEventListener("mousemove",mgMouseMove,true); | |
get_recent_conkeror_window().buffers.current.browser.removeEventListener("mouseup",mgMouseUp,true); | |
} | |
function mgConkerorHook(buffer) { | |
buffer.browser.addEventListener( "mousedown", mgMouseDown, true ); | |
} | |
add_hook("create_buffer_hook", mgConkerorHook ); | |
for_each_buffer( mgConkerorHook ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment