I made some more modifications to the Gesture extension. I made it a little more user friendly to modify the URL for a new tab, just modify the newTabURL variable.
I added a new "refresh" gesture, simply hold rightclick and move our mouse in a circle clockwise to refresh your current page. I found this useful for some projects I was working on. Its not pinpoint accurate to a circle but it works pretty good.
I also tweaked Waha's "click" feature, I added a CLICK_TIMEOUT which means that clicks must happen faster, if a timeout is reached it will not recognize your click. The default timeout is 1 second.
If you have any questions feel free to ask.
Code:/** READ THIS BEFORE EDITING **/ // Here you can create your own gestures. For the moment, how this works is that you create // a Gesture and an Action. // // _____________ // _____/ Terminology |___________________________________________________________________________________________________________________________ // | | // | Moves are either 'up', 'down', 'left', 'right' or 'click'. | // | | // | A Gesture is an array of Moves e.g.: myNewGesture = ["up","down","left"]. | // | - You should never have a Gesture that has two identical consecutive moves. e.g.: ["left","right","right"] is not a valid Gesture. | // | | // | An Action is a function that takes no parameters and has no return value. e.g.: myNewAction = function(){ alert("OMG!") } | // | | // | You can then configure ChromeGesture by modifying the myGestures array. | // | myGestures is an array where the index is your Gesture and the data is your Action. e.g.: myGestures[myNewGesture] = myNewAction; | // | - Do not use the same Gesture for two Actions. | // | | // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // // In case of doubt, drop by the forums on chromeplugins.org and ask. We'll answer ;) // ============ BEGIN STUFF YOU CAN (AND SHOULD) EDIT ============ var newTabGesture = ["down","right"]; var closeTabGesture = ["down","left"]; var historyBackGesture = ["left"]; var historyForwardGesture = ["right"]; var hidePageGesture = ["click","click"]; var refreshGesture = ["right","down","left","up","right"]; var newTabURL = "http://google.com"; // Change the default URL for a newTabGesture // TODO: Support for Chrome API function newTabAction() { window.open(newTabURL); } function closeTabAction() { window.close(); } function historyBackAction() { history.back(); } function historyForwardAction() { history.forward(); } function refreshAction() { location.reload(); } var isHiding = false; var page = null; var bgImage = null; function hidePageAction() { if(isHiding){ document.body.innerHTML = page; document.body.style.backgroundImage = bgImage; isHiding = false; } else { page = document.body.innerHTML; document.body.innerHTML = ""; bgImage = document.body.style.backgroundImage; document.body.style.backgroundImage = "none"; isHiding = true; console.log("Hiding?"); } } var myGestures = []; myGestures[newTabGesture] = newTabAction; myGestures[closeTabGesture] = closeTabAction; myGestures[historyBackGesture] = historyBackAction; myGestures[historyForwardGesture] = historyForwardAction; myGestures[hidePageGesture] = hidePageAction; myGestures[refreshGesture] = refreshAction; // ============ UNLESS YOU KNOW WHAT YOU ARE DOING, DON'T EDIT PAST HERE :) ============ // CONSTANTS var clickPast; var clickNow; var clickDiff; var ChromeGesture = { // If you think the Gesture detection sensitity too low, make these higher. MINIMUM_DELTAY : 10, // tweak this - Minimum Y distance that needs to be travelled between 2 captures for a move to be detected MINIMUM_DELTAX : 10, // tweak this - Same for X DELAY_BETWEEN_CAPTURES : 10, // tweak this - Time between captures CLICK_TIMEOUT : 1000, // tweak this - This is the timeout period between clicks (1000 = 1 second) LEFT_CLICK : 1, // Number associated with Left Click RIGHT_CLICK : 3, // Number associated with Right Click // Global variables pastX : 0, pastY : 0, currentGesture : [], pastTime : new Date(), // Functions captureGesture : function(event) { var currentTime = new Date(); var diff = currentTime.getTime() - ChromeGesture.pastTime.getTime(); var currentX = event.clientX; var currentY = event.clientY; ChromeGesture.printLine(currentX, currentY); if( diff < ChromeGesture.DELAY_BETWEEN_CAPTURES ){ return; } else { console.debug("Capture!"); var deltaX = currentX - ChromeGesture.pastX; var deltaY = currentY - ChromeGesture.pastY; console.log("Movement vector : (" + deltaX + ", " + deltaY + ")"); ChromeGesture.pastX = currentX; ChromeGesture.pastY = currentY; var move = ChromeGesture.determineMove(deltaX, deltaY); if( move != null ){ if( move != ChromeGesture.currentGesture[ChromeGesture.currentGesture.length - 1]){ ChromeGesture.currentGesture.push(move); } } console.warn("Moves : [" + ChromeGesture.currentGesture +"]"); ChromeGesture.pastTime = currentTime; } }, determineMove : function(deltaX, deltaY) { var absDeltaX = Math.abs(deltaX); var absDeltaY = Math.abs(deltaY); if( absDeltaX < ChromeGesture.MINIMUM_DELTAX && absDeltaY < ChromeGesture.MINIMUM_DELTAY ) { return null; } else { document.oncontextmenu = function(){return false;} // Gesture detected, hide the context menu } if( absDeltaY > absDeltaX ) { if( deltaY < 0 ){ return "up" } else { return "down" } } else { if( deltaX > 0 ){ return "right" } else { return "left" } } }, mouseButtonDown : function(event) { console.log("Mouse button down : " + event.which); if (event.which == ChromeGesture.RIGHT_CLICK){ //TODO: Don't stop propagation if time between mouseup / mousedown is < CONSTANT document.oncontextmenu = function(){return true;} // Right-click detected, enable the context menu ChromeGesture.pastX = event.clientX; ChromeGesture.pastY = event.clientY; window.addEventListener("mousemove", ChromeGesture.captureGesture); } }, mouseButtonUp : function(event) { console.log("Mouse button up : " + event.which); if(event.which == ChromeGesture.RIGHT_CLICK){ event.preventDefault(); event.stopPropagation(); clickPast = null; console.log("Removing event listener"); window.removeEventListener("mousemove", ChromeGesture.captureGesture); if(myGestures[ChromeGesture.currentGesture]){ // TODO: Support passing of parameters based on the origin of the gesture and such. myGestures[ChromeGesture.currentGesture](); } ChromeGesture.currentGesture = []; } else if (event.which == ChromeGesture.LEFT_CLICK){ if (!clickPast) { clickPast = new Date(); } clickNow = new Date(); clickDiff = Math.abs(clickPast.getTime() - clickNow.getTime()); console.log("CLICK DIFF : "+clickDiff); if (clickDiff < ChromeGesture.CLICK_TIMEOUT) { ChromeGesture.currentGesture.push("click"); document.oncontextmenu = function(){return false;} // Gesture detected, hide the context menu } clickPast = clickNow; } }, printLine : function() { // TODO: Print stuff next to cursor, track cursor position, append a div with text in document. } } // Initialization window.addEventListener("mousedown", ChromeGesture.mouseButtonDown, false); window.addEventListener("mouseup", ChromeGesture.mouseButtonUp, false);


LinkBack URL
About LinkBacks



Reply With Quote

