Welcome guest, is this your first visit? Create Account now to join.
Page 1 of 5 123 ... LastLast
Results 1 to 10 of 50

This is a discussion on Mouse Gesture UserScript within the Chrome Plugins section, part of the Google Chrome category: This is from Vhanla's post on "Another Site" (It is not created by me!!): Hi folks, today I will teach ...


  1. #1
    Stamga's Avatar
    Stamga is offline Super Moderator/Designer
    Join Date
    Mar 2009
    Location
    Qc, Canada
    Posts
    601

    Lightbulb Mouse Gesture UserScript

    This is from Vhanla's post on "Another Site" (It is not created by me!!):

    Hi folks, today I will teach you how to take advantage of the built-in userscript feature of Google Chrome to have a mouse gesture for navigating through history, I mean, back and forward.

    First you need to have that feature enabled, so you need to activate that with these simples steps (if you don't know how)

    For XP users go to Default folder (or the profile you're using) and create the directory "User Scripts" just like this
    C:\Documents and Settings\<you username>\Local Settings\Application Data\Google\Chrome\User Data\Default\User Scripts

    For Vista or 7 users
    C:\Users\Administrator\AppData\Local\Google\Chrome \User Data\Default\User Scripts

    After that you need to start Google Chrome with "--enable-user-scripts" parameter

    And finally the UserScript:
    Code:
    // ==UserScript==
    // @name Mouse Gestures for Google Chrome
    // @author vhanla
    // @namespace http://www.codigobit.net/ 
    // @version 1.0
    // @description Allows to use mouse gestures for navigating through pages
    // @include *
    // @exclude
    // ==/UserScript==
    
    (function() {
    
       var posx = 0;
       var estado = false; 
       var gestdown = function() {
           if (event.which)
                  button= (event.which < 2) ? "LEFT" :
                     ((event.which == 2) ? "MIDDLE" : "RIGHT");
           if (button=="RIGHT"){ 
             estado=true;
             posx=event.clientX;
             document.oncontextmenu = new Function("return false")
           }
       }
        var gestup = function() {        
            if (estado){
                estado=false;
                if(event.clientX+100<posx){                
                    window.history.back();                
                }
                else if(event.clientX-100>posx){                
                    window.history.forward();
                }
                else void(document.oncontextmenu=null)
            }
            
        }
        window.addEventListener("mousedown", gestdown, false);
        window.addEventListener("mouseup", gestup, false);
    })();
    Now open the Notepad and paste that code, and save that in the user scripts directory, remember that it must have js extension, so in order to succed, save as "mousegestures.user.js" with "" included inside of that directory.

    Ok, that is all, now you can hold the right button and drag back or forward in order to navigate.

    I prefer this method instead of having external programs.





    I don't know how to send keystrokes with javascript. However, I would suggest another method just like Opera.

    Code:
    // ==UserScript==
    // @name Mouse Gestures for Google Chrome
    // @author vhanla
    // @namespace http://www.codigobit.net/ 
    // @version 1.0
    // @description Allows to use mouse gestures for navigating through pages
    // @include *
    // @exclude
    // ==/UserScript==
    
    (function() {
    
       var posx = 0;
       var posy = 0;
       var estado = false; 
       var gestdown = function() {
           if (event.which)
                  button= (event.which < 2) ? "LEFT" :
                     ((event.which == 2) ? "MIDDLE" : "RIGHT");
           if (button=="RIGHT"){ 
             estado=true;
             posx=event.clientX;
             posy=event.clientY;
             document.oncontextmenu = new Function("return false")
           }
       }
        var gestup = function() {        
            if (estado){
                estado=false;
                if(event.clientX+50<posx){                
                    window.history.back();                
                }
                else if(event.clientX-50>posx){                
                    window.history.forward();
                }
    	    else if(event.clientY-50>posy){
    	        window.open("http://www.speedymarks.com");
    	    }
                else void(document.oncontextmenu=null)
            }
            
        }
        window.addEventListener("mousedown", gestdown, false);
        window.addEventListener("mouseup", gestup, false);  
    })();
    With Speedymarks you can emulate Opera's speed dial page. You don't need to be logged in if you want, and also you can set up to open in a different tab or in the same.



    Well for disabling you can add the following code into this existing one


    Code:
    var notooltips = function() {
    		var titles = document.getElementsByTagName("a");
    		for (var x = titles.length - 1 ; x>=0;x--)
    			titles[x].title = "";
    		var titlestd = document.getElementsByTagName("td");
    		for ( x = titlestd.length - 1 ; x>=0;x--)
    			titlestd[x].title = "";	
    		var alts = document.getElementsByTagName("img");
    		for (x = alts.length - 1 ; x>=0;x--)
    			alts[x].setAttribute('title','');
        }
    	window.addEventListener("load",notooltips, false);
    Maybe there is a better method to disable in all the page, but with this one you can only disable specific tags
    Last edited by Stamga; 04-15-2009 at 08:44 PM.

  2. #2
    alinescoo is offline Member
    Join Date
    May 2009
    Posts
    83

    Default

    This script stopped working a few versions ago. It's too bad because it was a feature that I really used it.

    I modified the script a little bit and now it looks like this:
    // ==UserScript==
    // @name Mouse Gestures for Google Chrome
    // @author vhanla
    // @namespace http://www.codigobit.net/
    // @version 1.0
    // @description Allows to use mouse gestures for navigating through pages
    // @include *
    // @exclude
    // ==/UserScript==

    (function() {

    var posx = 0;
    var posy = 0;
    var estado = false;
    var gestdown = function() {
    if (event.which)
    button= (event.which < 2) ? "LEFT" :
    ((event.which == 2) ? "MIDDLE" : "RIGHT");
    if (button=="RIGHT"){
    estado=true;
    posx=event.clientX;
    posy=event.clientY;
    document.oncontextmenu = new Function("return false")
    }
    }
    var gestup = function() {
    if (estado){
    estado=false;
    if(event.clientX+25<posx){
    window.history.back();
    }
    else if(event.clientX-25>posx){
    window.history.forward();
    }
    else if(event.clientY-25>posy){
    window.open();
    }
    else if(event.clientY+25<posy){
    window.close();
    }
    else void(document.oncontextmenu=null)
    }

    }
    window.addEventListener("mousedown", gestdown, false);
    window.addEventListener("mouseup", gestup, false);
    })();
    I kept trying to do a extension that includes this script. Because I am not familiar at all with extensions development I read a little on the net and I followed this steps:
    1. save the script as mousegestures.js
    2. I took a manifest.json from another extensions and modified it to take the mousegestures.js script
    3. I archived those two files into a zip file and renamed it to crx.
    4. I dragged the crx file into the main chrome window and it installed succesfully but no effect.

    Maybe someone with more experience can do this extension for us. It's really the missing piece in chrome.

  3. #3
    horatzica is offline Junior Member
    Join Date
    May 2009
    Posts
    5

    Default

    The new one doesn't work for me either

    My Chrome is 3.0.182.3 (dev channel). The only thing that I notice in Java Script console is this:
    Code:
    Uncaught TypeError: Cannot read property 'which' of undefined
    Is there any way to debug this script or any other way to help you make this work?

    Thanks

  4. #4
    alinescoo is offline Member
    Join Date
    May 2009
    Posts
    83

    Default

    So I guess that Chrome's new versions does not support event.which. I've searched around and couldn't find a replacement for it. I think if this is fixed, the first mouse gesture extension for Chrome it will be out. Anyone any ideas ?

    I can't see any message in Java Script Console. I tried replacing the first part of the script like this:
    (function() {

    var posx = 0;
    var posy = 0;
    var estado = false;
    var gestdown = function() {

    if (event.button==2){
    estado=true;
    posx=event.clientX;
    posy=event.clientY;
    document.oncontextmenu = new Function("return false")
    }

    Can you test it to see what message do you get ? Thank you
    Last edited by alinescoo; 06-01-2009 at 06:44 AM.

  5. #5
    horatzica is offline Junior Member
    Join Date
    May 2009
    Posts
    5

    Default

    No luck I tried with your changes but now I got:
    Code:
    Uncaught TypeError: Cannot read property 'button' of undefined
    I just tried a drag with the right button pressed and then I opened up the Java Script Console (Ctrl+Shift+j). On the bottom right I got an "error" icon that opens up the console with all the errors.

    I hope this helps you. Thanks

  6. #6
    alinescoo is offline Member
    Join Date
    May 2009
    Posts
    83

    Default

    With a friends help we managed to get the script running from a test page. I attach an example, just unzip those files to c: and open the sample page with Chrome. Right click and drag down, it should open a new tab.

    I don't know what to do to make it run on all chrome windows.... Anyone ? We are getting closer, I feel it
    Attached Files Attached Files
    Last edited by alinescoo; 06-01-2009 at 08:05 AM.

  7. #7
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    If you can place it into a page like you did, it should work as a content script / user script.
    If you try it and it doesn't work, post the error and i'll try to help.

  8. #8
    alinescoo is offline Member
    Join Date
    May 2009
    Posts
    83

    Default

    As I mentioned before, let's take for example the following version of the script:
    // ==UserScript==
    // @name Mouse Gestures for Google Chrome
    // @author vhanla
    // @namespace http://www.codigobit.net/
    // @version 1.0
    // @description Allows to use mouse gestures for navigating through pages
    // @include *
    // @exclude
    // ==/UserScript==

    (function() {

    var posx = 0;
    var posy = 0;
    var estado = false;
    var gestdown = function() {
    if (event.which)
    button= (event.which < 2) ? "LEFT" :
    ((event.which == 2) ? "MIDDLE" : "RIGHT");
    if (button=="RIGHT"){
    estado=true;
    posx=event.clientX;
    posy=event.clientY;
    document.oncontextmenu = new Function("return false")
    }
    }
    var gestup = function() {
    if (estado){
    estado=false;
    if(event.clientX+25<posx){
    window.history.back();
    }
    else if(event.clientX-25>posx){
    window.history.forward();
    }
    else if(event.clientY-25>posy){
    window.open();
    }
    else if(event.clientY+25<posy){
    window.close();
    }
    else void(document.oncontextmenu=null)
    }

    }
    window.addEventListener("mousedown", gestdown, false);
    window.addEventListener("mouseup", gestup, false);
    })();
    It works great with the sample page. I even start the page with "Open with" option from windows menu and started it in Chrome.exe without any start parameters.

    If I create User Scripts folder in Chrome profile folder and add --enable-user-script starup parameter, when I try to make a gesture in debug I get the folowing error (as mentioned above)

    Uncaught TypeError: Cannot read property 'which' of undefined
    in the script file.

    Whatever I tried to fix this, I couldn't. I could really use your help. Thank you.

    LE: I must say that in version 2.0.168.0 it works like a charm. So something must have changed in the latest builds. I'm sure it's just a little thing, but I am fully unexperienced with this.

  9. #9
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    Code:
    Uncaught TypeError: Cannot read property 'which' of undefined
    Does not mean that you can't use "which" on "event".
    It means that the "event" object is undefined.
    (It's kind of like a null pointer exception)

    Try passing as a parameter to the "gestdown" and "gestup" function an object named "event".

    Code:
    var gestdown = function() {
    would become
    Code:
    var gestdown = function(event) {
    Tell me if that helps.

  10. #10
    horatzica is offline Junior Member
    Join Date
    May 2009
    Posts
    5

    Default

    I can confirm that the script from the test page works great, even the back works (I opened the test page in an already open tab).

    I can always go back to 2.0.168.0 but I got the feeling that you are close too

Page 1 of 5 123 ... LastLast

Similar Threads

  1. Chrome Mouse Gestures?
    By Wisher in forum Chrome Plugins
    Replies: 40
    Last Post: 12-28-2010, 08:33 PM
  2. Back / forward buttons on mouse
    By Illway in forum Bugs and Vulnerabilities
    Replies: 1
    Last Post: 03-26-2009, 11:55 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
  •