Go Back   Google Chrome Forums > Google Chrome > Chrome Plugins


http://chromeplugins.org/frwrdicon.jpg
Top Tip : Click here to Boost Your PC & Chrome Browsing Speed
Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2009, 12:26 PM
Stamga's Avatar
Super Moderator/Designer
 
Join Date: Mar 2009
Location: Qc, Canada
Posts: 599
Send a message via MSN to Stamga
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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 05-29-2009, 07:54 AM
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:
Quote:
// ==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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 05-31-2009, 11:05 AM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 06-01-2009, 06:18 AM
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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 06-01-2009, 07:21 AM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 06-01-2009, 08:01 AM
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
File Type: zip Test.zip (873 Bytes, 121 views)

Last edited by alinescoo; 06-01-2009 at 08:05 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 06-01-2009, 11:08 AM
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.
__________________

ChromeGestures
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 06-01-2009, 11:44 AM
Member
 
Join Date: May 2009
Posts: 83
Default

As I mentioned before, let's take for example the following version of the script:
Quote:
// ==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)

Quote:
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 06-01-2009, 01:20 PM
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.
__________________

ChromeGestures
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 06-01-2009, 02:35 PM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chrome Mouse Gestures? Wisher Chrome Plugins 36 10-21-2009 03:16 AM
Back / forward buttons on mouse Illway Bugs and Vulnerabilities 1 03-26-2009 11:55 PM




Chrome Central - Chrome Talk - Chrome Tips and Tricks - Chrome Plugins - Chrome Themes - Chrome Tools - Bugs and Vulnerabilities - Chrome Tech - General Chat


All times are GMT. The time now is 02:12 PM.


Powered by vBulletin® Version 3.7.4 PL1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Google Chrome and Google™ is a Trademark of Google Inc
This site chromeplugins.org is not affiliated with or sponsored by Google Inc.
Thanks: Taree SEO Forum and John