Page 5 of 9 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 88

This is a discussion on ChromeGestures beta 0.1 within the Chrome Plugins section, part of the Google Chrome category: I made some more modifications to the Gesture extension. I made it a little more user friendly to modify the ...


  1. #41
    Kryptyx is offline Member
    Join Date
    Jul 2009
    Posts
    59

    Default

    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);

  2. #42
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    @LucVN

    lmao - How did I know it would be you ?

    @Kryptyx

    Just get it right and you go and change it ;-)

    PS: DoubleClick is a lot better now (Waha - not that it was that bad before) and quicker ;-D
    Last edited by StevePaul; 07-14-2009 at 06:09 PM. Reason: Added PS:

  3. #43
    Luc VN's Avatar
    Luc VN is offline Senior Member
    Join Date
    Sep 2008
    Location
    Belgium - Europe
    Posts
    758

    Default

    @ StevePaul: You kind of provoked it, no?

  4. #44
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    @LucVN; Oui !!

  5. #45
    Kryptyx is offline Member
    Join Date
    Jul 2009
    Posts
    59

    Default

    I have recompiled the extension with all the recent changes, you may now download it by rightclicking and choosing "save link as".

    ChromeGestures v1.0

    Any questions, comments or issues please let me know!

  6. #46
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    Blooming 'eck ...

    I've just spent half an hour on the Chrome Help Forum explaining how to download the original and then customise it ;-)

  7. #47
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    The Reload Gesture is a nice addition, extremely useful for sites where Waha's Click doesn't restore the page (Facebook) ...

    One last thing (I promise) as the JavaScript can be used as a User Script could you provide a download to this extension as a User Script, then people who are not as adventurous as us (Ie Stable/Beta users) can enjoy the benefits ...

    The only thing they would need to do then (if they wanted) is edit the JS and change the NewTab default page to their choice...

    I know they could UnZip the download file to get at the JS and then rename it by adding .user

    Would be a lot more professional if we (I mean you) did it for them ;-)
    Last edited by StevePaul; 07-14-2009 at 08:49 PM.

  8. #48
    Kryptyx is offline Member
    Join Date
    Jul 2009
    Posts
    59

    Default

    Quote Originally Posted by StevePaul View Post
    The Reload Gesture is a nice addition, extremely useful for sites where Waha's Click doesn't restore the page (Facebook) ...

    One last thing (I promise) as the JavaScript can be used as a User Script could you provide a download to this extension as a User Script, then people who are not as adventurous as us (Ie Stable/Beta users) can enjoy the benefits ...

    The only thing they would need to do then (if they wanted) is edit the JS and change the NewTab default page to their choice...

    I know they could UnZip the download file to get at the JS and then rename it by adding .user

    Would be a lot more professional if we (I mean you) did it for them ;-)
    I'm not familiar with the "user scripts" your talking about. Can you show me a demonstration?

    On a side note, an easy way to modify the extension is to simply edit the JS file in the extensions folder. Open it up in any text editor and change the newTabURL variable.

    If I can make this easier for people to modify though using the user script thing you mentioned just point me in the right direction and I will look into it.

  9. #49
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    Personally, I'm OK with editing the JS file and have substituted my preferred URL in the variable and am really happy with the outcome ...

    As for User Scripts, these were the forerunners to extensions (still extensively used, especially i n the Stable/Beta environments)and used JS like your extension does ...

    However for them to work in Chrome you had to save them as a special JS file

    So where your extension uses ChromeGestures.js, a User Script has to be saved as ChromeGestures.user.js (the .user being the most important part),

    For users to be able to use your extension as a User Script it needs to be saved in this format ...

    So what is actually needed is two downloads ...

    One for the Extension (which we've already got) and one for the User Script (with just the JS saved in the correct format)...

    You can find examples of user scripts here ...
    Chrome Extensions, Bookmarklets & Userscripts Compilation

    Hope this all makes sense ;-)

  10. #50
    Kryptyx is offline Member
    Join Date
    Jul 2009
    Posts
    59

    Default

    I looked into it some more, I can support userscripts if there is enough need for it but right now the primary focus for me is the extension system since thats what will be more standard. There is some syntax changes to make the userscripts to work so thats why I'm a little hesitant to start with that.

Page 5 of 9 FirstFirst ... 34567 ... LastLast

Similar Threads

  1. Chrome Officially Out of Beta
    By Chrome in forum Chrome Talk
    Replies: 1
    Last Post: 12-16-2008, 05:39 PM
  2. Chrome To Come Out Of Beta
    By Chrome in forum Chrome Talk
    Replies: 0
    Last Post: 12-10-2008, 12:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •